assert with status codes
npm install http-assert[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][ci-image]][ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Assert with status codes. Like ctx.throw() in Koa, but with a guard.
This is a Node.js module available through the
npm registry. Installation is done using thenpm install command:
``bash`
$ npm install http-assert
js
var assert = require('http-assert')
var ok = require('assert')var username = 'foobar' // username from request
try {
assert(username === 'fjodor', 401, 'authentication failed')
} catch (err) {
ok(err.status === 401)
ok(err.message === 'authentication failed')
ok(err.expose)
}
`API
The API of this module is intended to be similar to the
Node.js
assert module.Each function will throw an instance of
HttpError from
the http-errors module
when the assertion fails.$3
Tests if
value is truthy. If value is not truthy, an HttpError
is thrown that is constructed with the given status, message,
and properties.$3
Tests for deep equality between
a and b. Primitive values are
compared with the Abstract Equality Comparison (==). If a and b
are not equal, an HttpError is thrown that is constructed with the
given status, message, and properties.$3
Tests shallow, coercive equality between
a and b using the Abstract
Equality Comparison (==). If a and b are not equal, an HttpError
is thrown that is constructed with the given status, message,
and properties.$3
Always throws an
HttpError that is constructed with the given status,
message, and properties.$3
Tests for deep equality between
a and b. Primitive values are
compared with the Abstract Equality Comparison (==). If a and b
are equal, an HttpError is thrown that is constructed with the given
status, message, and properties.$3
Tests shallow, coercive equality between
a and b using the Abstract
Equality Comparison (==). If a and b are equal, an HttpError is
thrown that is constructed with the given status, message, and
properties.$3
Tests strict equality between
a and b as determined by the SameValue
Comparison (===). If a and b are equal, an HttpError is thrown
that is constructed with the given status, message, and properties.$3
Tests if
value is truthy. If value is not truthy, an HttpError
is thrown that is constructed with the given status, message,
and properties.$3
Tests strict equality between
a and b as determined by the SameValue
Comparison (===). If a and b are not equal, an HttpError
is thrown that is constructed with the given status, message,
and properties`.[ci-image]: https://badgen.net/github/checks/jshttp/http-assert/master?label=ci
[ci-url]: https://github.com/jshttp/http-assert/actions?query=workflow%3Aci
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/http-assert/master
[coveralls-url]: https://coveralls.io/r/jshttp/http-assert?branch=master
[node-version-image]: https://badgen.net/npm/node/http-assert
[node-version-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/http-assert
[npm-url]: https://npmjs.org/package/http-assert
[npm-version-image]: https://badgen.net/npm/v/http-assert