http-error.js
Error class for Octokit request errors
Usage
Browsers
|
Load @octokit/request-error directly from esm.sh
<script type="module">
import { RequestError } from "https://esm.sh/@octokit/request-error";
</script>
|
---|
Node
|
Install with npm install @octokit/request-error
import { RequestError } from "@octokit/request-error";
|
---|
[!IMPORTANT]
As we use conditional exports, you will need to adapt your tsconfig.json
by setting "moduleResolution": "node16", "module": "node16"
.
See the TypeScript docs on package.json "exports".
See this helpful guide on transitioning to ESM from @sindresorhus
const error = new RequestError("Oops", 500, {
request: {
method: "POST",
url: "https://api.github.com/foo",
body: {
bar: "baz",
},
headers: {
authorization: "token secret123",
},
},
response: {
status: 500,
url: "https://api.github.com/foo",
headers: {
"x-github-request-id": "1:2:3:4",
},
data: {
foo: "bar",
},
},
});
error.message;
error.status;
error.request;
error.response;
Usage with Octokit
try {
await octokit.request("GET /");
} catch (error) {
if (error.status) {
} else {
throw error;
}
}
LICENSE
MIT