Skip to content

Create simple error objects with custom properties for reuse in your code.

License

Notifications You must be signed in to change notification settings

leothelocust/custom-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

custom-errors

Create simple error objects with custom properties for reuse in your code.

Not for production use

This is intended to aid in development. It includes the stack trace in the response and so unless its modified to remove that parameter or make it properly conditional based on env, this is not for production use.

Example

import * as CustomError from 'custom-errors'

let msgObj = {
  message: 'Custom error message',
  display_message: 'Separate message to potentially display to an end user'
}

// Multiple boilerplate error objects like:
// Validation, Unauthorized, TokenExpired, etc...

console.error(CustomError.Validation(msgObj))

// will look something like the following
{
    name: 'Validation Failed',
    message: 'Custom error message',
    display_message: 'Separate message to potentially display to an end user',
    status: 400,
    err: {newly created Error Object to obtain a stack},
    stack: err.stack
}

About

Create simple error objects with custom properties for reuse in your code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published