New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

allanchau-http-error

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allanchau-http-error

Simple Express HTTP error handler.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-64.29%
Maintainers
1
Weekly downloads
 
Created
Source

node-http-error

npm Report coverage Test

Simple Express HTTP error response middleware.

Features

  • Simple API error responses.

Installation

This package is available on NPM:

$ yarn add allanchau-http-error

Usage

A simple example:

// App.
const app = require("express");
const httpError = require("allanchau-http-error");

app.use(httpError());

app.get("/stringexample", (req, res, next) => {
  return res.error("Oops something went wrong.");
});

// Returns
// {
//   "code": "400",
//   "message": "Oops something went wrong.",
// }

app.get("/errorobjectexample", (req, res, next) => {
  return res.error(new Error("Oops something went wrong."));
});

// Returns the same thing
// {
//   "code": "400",
//   "message": "Oops something went wrong.",
// }

app.get("/customerrorexample", (req, res, next) => {
  return res.error({
    code: "ERRBADREQUEST",
    message: "Oops something went wrong.",
  });
});

// Returns
// {
//   "code": "ERRBADREQUEST",
//   "message": "Oops something went wrong.",
// }

You can also provide some defaults for the route.

app.use(
  httpError({
    defaultCode: "ERRNOTAUTHORIZED",
    defaultMessage: "The user is not authorized.",
    defaultStatusCode: 401,
  })
);

app.get("/stringexample", (req, res, next) => {
  return res.error();
});

// Returns
// {
//   "code": "ERRNOTAUTHORIZED",
//   "message": "The user is not authorized.",
// }

Keywords

FAQs

Package last updated on 10 Apr 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