This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@loves/loves-web-error-handler

0.4.0 • Public • Published

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.')

unauthorized(message, errorCode) -- Creates a 401 with customizable error messaging (Default: 'Access is denied due to invalid credentials.')

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.

Readme

Keywords

none

Package Sidebar

Install

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

Weekly Downloads

11

Version

0.4.0

License

ISC

Last publish

Collaborators

  • coderdad
  • nlindley
  • xingwang