How to use the http-errors.HttpError function in http-errors

To help you get started, we’ve selected a few http-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / http-errors_v1.x.x / test_http-errors_v1.x.x.js View on Github external
import HttpErrors from 'http-errors';

const A: HttpErrors.HttpError = new HttpErrors.HttpError();
const B: HttpErrors.HttpError = HttpErrors();
const C: HttpErrors.HttpError = HttpErrors(200, 'foo', {});
// $ExpectError
const D: HttpErrors.HttpError = HttpErrors('500');
const E: HttpErrors.NotFound = new HttpErrors.NotFound();
const F: HttpErrors.HttpError = new HttpErrors.LengthRequired;
const G: HttpErrors.HttpError = new HttpErrors.HttpError('foo');

(F.expose: bool);
(F.message: string);
(F.status: number);
(F.statusCode: number);
github koajs / koa / test / application / index.js View on Github external
it('should have a static property exporting `HttpError` from http-errors library', () => {
    const CreateError = require('http-errors');

    assert.notEqual(Koa.HttpError, undefined);
    assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError);
    assert.throws(() => { throw new CreateError(500, 'test error'); }, Koa.HttpError);
  });
});
github microsoft / pai / src / rest-server / src / utils / error.js View on Github external
const createUnknownError = exports.unknown = (cause) => {
    if (cause instanceof httpErrors.HttpError) {
        return cause;
    }
    const message = cause instanceof Error ? cause.message : String(cause);
    const error = createError('Internal Server Error', 'UnknownError', message);
    if (cause instanceof Error) {
        error.stack = cause.stack;
    } else {
        Error.captureStackTrace(error, createUnknownError);
    }
    return error;
};
github fastify / fastify-sensible / lib / httpErrors.js View on Github external
notExtended: function notExtended (message) {
    return new createError.NotExtended(message)
  },

  networkAuthenticationRequired: function networkAuthenticationRequired (message) {
    return new createError.NetworkAuthenticationRequired(message)
  }
}

function getHttpError (code, message) {
  return httpErrors[statusCodesMap[code + '']](message)
}

module.exports = httpErrors
module.exports.getHttpError = getHttpError
module.exports.HttpError = createError.HttpError