Fashy Errors is an npm package that provides a simple way to handle errors in your Node.js / Express application.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install fashy-errors
To use Fashy Errors as the global error handler middleware in your Express application, you can simply import the GlobalErrorHandler function from the package and use it as middleware:
const express = require('express');
const { GlobalErrorHandler } = require('fashy-errors');
const app = express();
app.get('/', (req, res, next) => {
res.json({
status: 'success',
message: 'Hello world',
});
});
// Global Error Handler Middleware
app.use(GlobalErrorHandler);
app.listen(4000, () => console.log(`Server running`));
You can also create and use custom errors in your application by importing the CustomError class from the package and throwing a new error with it:
const { CustomError } = require('fashy-errors');
app.all('*', (req, res, next) => {
// Custom Error Message
throw new CustomError('Page not found !!!', 404);
});
Contributions to this project are welcome 🤗. Feel free to open issues and submit pull requests.
Fashy Errors is licensed under the MIT License. See the LICENSE file for more information.
Fashy Errors is developed by Kenechukwu Arionye. You can contact me at kenechiaugustine@gmail.com