![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@octokit/request-error
Advanced tools
The @octokit/request-error npm package is designed to handle errors that occur during requests made using the Octokit library, which is a GitHub API client. It provides a structured way to catch and process errors, making it easier to debug and handle exceptions in applications that interact with GitHub's API.
Creating a RequestError instance
This feature allows developers to create an instance of RequestError, providing a message, status code, and request details. This can be useful for simulating errors in tests or handling errors in a structured way.
const { RequestError } = require('@octokit/request-error');
const error = new RequestError('Message describing the error', 404, {
request: {
method: 'GET',
url: 'https://api.github.com/repos/octocat/Hello-World',
headers: {
authorization: 'token secret123'
}
}
});
Accessing error details
Once a RequestError instance is created, developers can access various details about the error, such as the HTTP status code, error message, and the request that caused the error. This is particularly useful for logging and debugging purposes.
const error = new RequestError('Not Found', 404, {
request: {
method: 'GET',
url: 'https://api.github.com/repos/octocat/Hello-World',
headers: {
authorization: 'token secret123'
}
}
});
console.log(error.status); // 404
console.log(error.message); // Not Found
console.log(error.request.method); // GET
axios-error is a package that provides a similar functionality for Axios, a popular HTTP client. It wraps errors thrown by Axios requests in a more descriptive object, similar to how @octokit/request-error works for Octokit. However, it is specifically tailored for Axios and its error handling patterns.
http-errors is a package for creating HTTP error objects. While it does not directly handle errors from HTTP requests like @octokit/request-error, it provides a way to create error objects with status codes and messages, which can be used in a variety of web applications and APIs.
Error class for Octokit request errors
Browsers |
Load @octokit/request-error directly from esm.sh
|
---|---|
Node |
Install with
|
[!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; // Oops
error.status; // 500
error.request; // { method, url, headers, body }
error.response; // { url, status, headers, data }
try {
// your code here that sends at least one Octokit request
await octokit.request("GET /");
} catch (error) {
// Octokit errors always have a `error.status` property which is the http response code
if (error.status) {
// handle Octokit error
} else {
// handle all other errors
throw error;
}
}
FAQs
Error class for Octokit request errors
The npm package @octokit/request-error receives a total of 7,791,478 weekly downloads. As such, @octokit/request-error popularity was classified as popular.
We found that @octokit/request-error demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.