1.0.0 • Published 3 years ago

@theflyinghorse/http-exception v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

http-exception

HTTP error package

How to use

const httpExceptions = require('http-exception');

function x(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.BadRequestException());
  }
}

function x2(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.BadRequestException('custom message', {
      code: 'CUSTOM_CODE',
      data: {
        foo: 'bar'
      }
    }));
  }
}

function y(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.NotFoundException());
  }
}

function y2(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.NotFoundException('custom message', {
      code: 'CUSTOM_CODE',
      data: {
        foo: 'bar'
      }
    }));
  }
}

function z(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.UnauthorizedException());
  }
}

function z2(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.UnauthorizedException('custom message', {
      code: 'CUSTOM_CODE',
      data: {
        foo: 'bar'
      }
    }));
  }
}

function z(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.InternalServerException());
  }
}

function z2(req, res, next) {
  try {
    // do something
  } catch (err) {
    next(httpExceptions.InternalServerException('custom message', {
      code: 'CUSTOM_CODE',
      data: {
        foo: 'bar'
      }
    }));
  }
}