2.13.0 β€’ Published 22 days ago

error-manager-helper v2.13.0

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

π‘¬π’“π’“π’π’“π‘΄π’‚π’π’‚π’ˆπ’†π’“ πŸŒŸπŸ’»

  • This module provides you with custom errors for your express app and helps you to integrate them easily. Use them in your application for specific error types.

With express

This is how your express server file would look like:

import express from 'express'

// ==== ErrorManager() ====
import errorManager from 'error-manager-helper'
const { errorMiddleware } = errorManager

const app = express()

// Define your routes here..

// errorMiddleware is error handle middleware which will be triggered when you throw error.
app.use(errorMiddleware)

const server = app.listen(port)
console.log(`Server is running on port ${port}`)

Without express

  • If you are not using express then you can still require the error types. But then they will only throw the error and not send it to the client
import { ValidationError } from 'error-manager-helper'

export default class Manager {
    constructor(chain: string) {
        if (!chain) {
            throw new ValidationError('Manager() - Argument chain is invalid', { chain })
        }
    }
}


πΈπ“‡π“‡π‘œπ“‡π“ˆ πŸŒŸπŸ’»

𝑩𝒂𝒔𝒆𝑬𝒓𝒓𝒐𝒓 🚨

  • Will be always HTTP Status 500
  • Passing error is optional
throw new BaseError('Your Error Title', new Error('Any Error'))

𝐇𝐭𝐭𝐩𝐂π₯π’πžπ§π­π„π«π«π¨π« 🌐

  • At the moment working with those HTTP clients:

    • axios
  • Will be the status of the error of your HTTP request

try {
    await axios.get(`${BASE_URL}/notFound`)
} catch (e) {
    throw new HttpClientError('Your Error Title', e)
}

π‘½π’‚π’π’Šπ’…π’‚π’•π’Šπ’π’π‘¬π’“π’“π’π’“ ❌

  • Will be always HTTP Status 400
  • Passing error is optional
throw new ValidationError('Your Error Title', { dataThatNotValid }, new Error('Any Error'))

𝑹𝒆𝒔𝒐𝒖𝒓𝒄𝒆𝑡𝒐𝒕𝑭𝒐𝒖𝒏𝒅𝑬𝒓𝒓𝒐𝒓 πŸ”

  • Will be always HTTP Status 404
  • Passing error is optional
throw new ResourceNotError('Your Error Title', dataThatMissed, new Error('Any Error'))

π‘Ήπ’–π’π‘»π’Šπ’Žπ’†π‘¬π’“π’“π’π’“ ⏳

  • You can define custom HTTP status
  • Passing error is not optional
throw new RunTimeError('Your Error Title', errorHere, customHttpStatus)


npm_lifecycle_event πŸ”§πŸ› οΈ

  • When you use npm_lifecycle_event:start then your error message and stacktrace will not be sended to the client. Sample response:
{
    "environment":"start",
    "title":"collectionName can not contain special characters",
    "errorMessage":null,
    "stack":null
}
  • With all other npm_lifecycle_event errorMessage and stack will be included. This is usefully if you to not want to send sensitive details to the client on production but on the other side want them local in dev.
    • However, even with npm_lifecycle_event:start the full error will be always logged to the terminal of your APP.
2.12.0

22 days ago

2.13.0

22 days ago

2.3.0

1 month ago

2.2.0

1 month ago

2.6.0

1 month ago

2.9.0

29 days ago

2.1.0

1 month ago

1.2.0

1 month ago

1.0.0

1 month ago