
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
rest-api-errors
Advanced tools
Common errors that can be thrown to simplify promise based api implementations
It's a set of errors that can be thrown to break a promise chain in a clean and logical way when creating APIs using NodeJS. I created it because I like promises and I like rest and I like simple. It also keeps me from having to remember the right http status codes to return for various errors.
Here's an example of an endpoint to delete a Thang.
// delete a thang
app.delete('/thangs/:id', function (req, resp) {
var username = req.user.username;
var id = req.params.id;
Thang.findOne({
_id: id
}).then(thang => {
if (!thang) {
// give em a 404 with custom error code and message
throw new NotFoundError('thang_not_found', "I can't find that thang :(");
} else if (thang.createdBy !== username) {
// give em a generic 403
throw new ForbiddenError();
}
// it's all good so actually delete the thang
return Thang.deleteOne({
_id: id
});
}).then(function () {
resp.status(204).end();
}).catch(function (err) {
if(err instanceof ApiError) {
// handle any ApiError with a simple elegant response
resp.status(err.status).send({
code: err.code,
message: err.message
});
} else {
// handle all other errors in some kinda way
handleError(resp, err);
}
});
};
All of following are implemented. Throw them to your hearts content.
FAQs
Common errors that can be thrown to simplify promise based api implementations
The npm package rest-api-errors receives a total of 191 weekly downloads. As such, rest-api-errors popularity was classified as not popular.
We found that rest-api-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.