This module is used internally by Rill but is extracted for convenience. Utility for generating HttpError's with messages, codes and meta data.
npm install @rill/error
import HttpError, { assert, fail } from "@rill/error";
new HttpError(404); //-> [HttpError Not Found]
fail(404); //-> throws [HttpError Not Found]
assert(false, 404); //-> throws [HttpError Not Found]
assert(true, 404); //-> Does nothing
- HttpError(statusCode, [statusMessage], [metaData]) : Creates a new HttpError.
- HttpError.fail(statusCode, [statusMessage], [metaData]) : Creates a new HttpError and automatically throws it.
- HttpError.assert(value, statusCode, [statusMessage], [metaData]) : Creates a new HttpError and automatically throws it if value is falsey.
Use npm test
to run tests.
Please feel free to create a PR!