rill-js / error

💥 The http error function used in Rill.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rill
@rill/error
API Stability TypeScript Styled with prettier Build status Test Coverage NPM Version Downloads Browser Bundle Size

This module is used internally by Rill but is extracted for convenience. Utility for generating HttpError's with messages, codes and meta data.

Installation

npm install @rill/error

Example

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

API

  • 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.

Contributions

Use npm test to run tests. Please feel free to create a PR!

About

💥 The http error function used in Rill.


Languages

Language:TypeScript 100.0%