Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
make your express application respond correctly when http requests are failing
Make sure your express application responds correctly when outgoing http requests are failing
When your express application is calling failing resources, mount this middleware to ensure it will respond with a proper 502 Bad Gateway
response when needed.
$ npm install anubis --save
This is a tiny express app that will do nothing but proxy another resource. In case the call fails with a 5xx error, anubis makes sure the correct 502
status code is returned.
var express = require('express');
var rp = require('request-promise');
var anubis = require('anubis');
var app = express();
app.get('/', function(req, res, next){
rp('http://my-unreliable-api.com')
.then(function(payload){
res.json({ok: true, payload: payload});
})
.catch(next);
});
// always make sure to mount anubis **after** all routes that call
// external resources
// pass a function that transforms the Error into a status code
app.use(anubis(function(err){
return err.statusCode;
}));
app.use(function(err, req, res, next){ //eslint-disable-line no-unused-vars
res.status(err.status);
res.json({ok: false});
});
MIT © Frederik Ring
FAQs
make your express application respond correctly when http requests are failing
The npm package anubis receives a total of 0 weekly downloads. As such, anubis popularity was classified as not popular.
We found that anubis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.