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

@loves/loves-web-error-handler

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loves/loves-web-error-handler

A web error handler that formats responses.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
3
Weekly downloads
 
Created
Source

Love's Web Error Handler

A library to format errors as JSON to send back to web clients based on where the application is running.

Installation

npm install @loves/loves-web-error-handler

Usage

Creates consistent web api errors in the format:

{
  statusCode: 500,
  errorCode: '',
  message: '',
  errors: [
    {
      field: '',
      message: ''
    }
  ]
}

const lovesErrorHandler = require('@loves/loves-web-error-handler');

formatError(err) -- Converts Error object to above. Retains all above fields if provided.

badRequest(message, errorCode) -- Creates a 400 with customizable error messaging (Default: 'Invalid request.')

resourceNotFound(message, errorCode) -- Creates a 404 with customizable error messaging (Default: 'The requested resource could not be found.')

internalServerError(message, errorCode) -- Creates a 500 with customizable error messaging (Default: 'An error has occurred.')

validationError(message, errorCode) -- Creates a 422 with customizable error messaging (Default: 'Form validation failed.')

addValidationError(err, field, message) -- Appends field level validation error messaging to existing error object.

FAQs

Package last updated on 20 Sep 2017

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