2.13.0 β’ Published 22 days ago
error-manager-helper v2.13.0
π¬πππππ΄ππππππ ππ»
- 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.