
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@apparts/error
Advanced tools
HttpError Object and some helper functions for handling Errors in a Http environment
#+TITLE: @apparts/errors #+DATE: [2021-02-11 Thu] #+AUTHOR: Philipp Uhl
An error-element used together with [[https://github.com/phuhl/apparts-types][@apparts/types]]. When returned or thrown within a function that is given to the preparator function (or prepauth, etc.), it will produce the corresponding HTTP error.
With the =fromThrows= helper function, you can remove nasty =try {} catch(e) {}= phrases that should return a value and normally require a non constant variable.
#+BEGIN_SRC js const { HttpError, fromThrows } = require("@apparts/error");
// within @apparts/types preperator function: preperator({}, async () => { const somethingWrong = "blub"; if(somethingWrong) { return new HttpError(400, "You specified that parameter wrong", "Some dynamic info: " + somethingWrong); // --> http-statuscode 400, body: { error: "You specified that parameter wrong", // description: "Some dynamic info: blub" } } throw new HttpError(412, "Want to throw"); // --> http-statuscode 412, body: { error: "Want to throw" }
return HttpError.notFound("My element"); // --> http-statuscode 404, body: { error: "My element not found" }
if (!allowed) {
return new HttpError(403); // --> http-statuscode 403, body: { error: "Forbidden" }
}
const data = fromThrows(() => JSON.parse("ha, you cant parse this!"),
SyntaxError,
e => new HttpError(400, "The data you send could net be parsed", e));
// If function throws SyntaxError, error will be re-thrown as 400-HttpError.
// If function throws different error, that error will be re-thrown (should give
// thanks to you a 500 server error thanks to preperator).
// If function returns normally, it's result is returned by fromThrows.
}); #+END_SRC
FAQs
HttpError Object and some helper functions for handling Errors in a Http environment
We found that @apparts/error 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.