![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
An ExpressJS middleware to handle custom errors.
npm install --save fi-errors
The first step is to create your configuration file. Here you can define your custom errors, redirection urls and excluded requests.
This package comes with a default configuration that you can extend or overwrite.
const config = {
// Custom application errors
errors: [
// This error will be added to the component errors list
{
name: 'EnhanceYourCalmError',
message: 'Breath in... Breath out...'
code: 420
},
// This errors will overwrite the default errors with new messages
{
name: 'BadRequestError',
message: 'The request could not be understood by the server due to malformed syntax.'
code: 400
}, {
name: 'ConflictError',
message: 'This document is already registered.',
code: 409
}
],
// Application custom error handlers
handlers: {
// Handle validations errors with BadRequestError
'ValidationError': 'BadRequestError',
// Handle errors with code 11000 with MongoDuplicatedError
'11000': 'DuplicatedEntityError'
},
// Every failed HTTP request to this urls will be terminated
exclude: /^\/(assets|api)\//i,
// Redirection urls
redirect: {
error: '/error?err=',
lost: '/lost?url='
},
// Function to use for debugging
debug: err => {
console.log('START ERROR LOG:', new Date());
console.log(err);
console.log('END ERROR LOG:', new Date());
},
// Condition to debug an error
shouldDebug: err => err.code > 399
};
To use the package you must configure it and then bind it to the express application.
const errors = require('fi-errors');
const express = require('express');
const app = express();
// Configure the module
errors.config(config);
// Register other middlewares
// app.use(...);
// Optionally, use the fi-errors not found (404) middleware
app.use(errors.notFoundMiddleware);
// Lastly, bind the fi-errors handler
app.use(errors.handler);
const errors = require('fi-errors');
const { BadRequestError } = errors;
module.exports = (router, db) => {
const User = db.model('user');
/**
* Creates a user.
*/
router.post('/', (req, res, next) => {
User.create(req.body)
.then(user => {
if (!user) {
throw new BadRequestError('The user could not be created');
}
res.status(HTTP_CODE_CREATED).json(user._id);
})
// Any ValidationError catched here will be handled with BadRequestError.
// Any error with code 11000 catched here will be handled with
// DuplicatedEntityError.
.catch(next);
});
});
Every error triggered in a middleware will be catched inside the component.
Read the library docs for the methods specification.
FAQs
Error manangement middleware for ExpressJS
We found that fi-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.