Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Latest commit

 

History

History
37 lines (25 loc) · 745 Bytes

README.md

File metadata and controls

37 lines (25 loc) · 745 Bytes

Archived

Please use node built in assert instead.

const assert = require('assert');
const httpErrors = require('http-errors');

assert.ok(false, new httpErrors.NotFound(`I'm not here, look elsewhere`);

throw-if-true

A tiny utility to throw error if given param is truthy.

Install

$ npm install throw-if-true

Examples

const httpErrors = require('http-errors');
const throwIfTrue = require('throw-if-true');

const doc = functionThatReturnsFromDb();

// Throws Error with no message
throwIfTrue(!!doc);

// Throws Error with message 'Doc is not set'
throwIfTrue(!!doc, 'Doc is not set');

// Throws NotFoundError with message 'Doc not set'
throwIfTrue(!!doc, httpErrors.NotFound, 'Doc not set');