Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

app-exception

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-exception

A small and easy-to-use http errors library for Node

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

AppException

AppException is a small and easy-to-use HTTP error library for Node. It's an addition to HttpException

Exceptions vs Errors

Features

AppException improves HttpException work making easier to create errors with custom application codes.

Node's http module

How to Use

import AppException from 'app-exception';

// via the AppException class. Parameters: message, application error code, http error code
const errorOne = new AppException('error message', 9, 500);

// via the createError factory
const errorTwo = AppException.createError();

// via AppException's static HTTP status-specific methods
throw AppException.internalServerError('test', 9);
throw AppException.badRequest('test', 9);

Integration with Express.js

const app = express();

// other stuff

// after all your app.use
app.use(async function (err, req, res, next) {
    if(err instanceof HttpException) {
        return res.status(err.status).json(err);
    }

    // other error handling stuff
});

Catching any exception and returning as response with Express.js

const app = express();

// first app.use
app.use(function (req, res, next) {
    Response.response(res);
    next();
});

Syntax

AppException[httpStatusType]([message], [code])

AppException.internalServerError([message], [code])

AppException.badRequest([message], [code])

  • message { String } error message
  • code { String / Integer } application error code

Returns a new AppException object.

const error = AppException.badRequest({
  message: 'No user found',
  code: 9
})

throw error

new AppException([message], [code], [status])

  • message { String } error message
  • code { String / Integer } application error code
  • status { Integer } http error code

Returns a new AppException object.

throw new AppException('error', 9, 400)

AppException.createError([options])

  • options { Object }

Return a new AppException object.

const error = AppException.createError({
  message: 'No user found',
  code: 9,
  status: 400
})

throw error

Contact

For support and questions contact mail me at team@99xp.org

Licence

MIT

Keywords

FAQs

Package last updated on 20 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc