Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@songkick/promise-reject-status-above
Advanced tools
Rejects a promise returned by fetch() if status above threshold
Rejects a promise returned by fetch()
if status above threshold
var rejectStatusAbove = require('promise-reject-status-above');
var rejectAbove400 = rejectStatusAbove({status: 400});
function fetch200(){
return fetch('/path/to/a/http-200-ok');
}
function fetch400(){
return fetch('/path/to/a/http-400-bad-request');
}
rejectAbove400(fetch200)()
.then(function(response){
// the initial fetch response
}).catch(function(err){
// probably won't happen here, unless /200 doesn't return a HTTP - 200
});
rejectAbove400(fetch400)()
.then(function(response){
// should not happen here
}).catch(function(err){
// err instanceof rejectStatusAbove.StatusAboveError === true
// err === {
// message: 'Response status above accepted status',
// settings: {
// status: 400,
// },
// fn: fetch400,
// response: window.Response // the original fetch Response
// }
});
status
: positive (>= 0) number. The returned promise will be rejected if the
response's status is equal or above this number.
As promise-reject-status-above
input and output is a function returning a promise, you can compose them easily with other simial helpers (see below).
In the example below, our /data
API is a bit janky and might return HTTP 500 errors. We'll retry them twice before giving up.
var promiseRetry = require('promise-retry');
var rejectStatusAbove = require('promise-reject-status-above');
var retryTwice = promiseRetry({ retries: 2 });
var rejectAbove500 = rejectStatusAbove({status: 500});
function fetchData() {
// this call might return 500 sometimes
return fetch('/data');
}
retryTwice(rejectAbove500(fetchData))().then(function(response){
// yay !
}).catch(function(err){
// we retried the call twice but always got 500s :(
});
promise-reject-status-above
composes really well with the following promise helper:
FAQs
Rejects a promise returned by fetch() if status above threshold
The npm package @songkick/promise-reject-status-above receives a total of 0 weekly downloads. As such, @songkick/promise-reject-status-above popularity was classified as not popular.
We found that @songkick/promise-reject-status-above 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.