fetch-plus
fetch-plus copied to clipboard
Support async error handlers
I needed this because I want to be able to do get the error response with errorResponse.text()
and put it in the error message. It could also help in other middleware if they need to fire off a second request the first one fails etc. It should be backwards compatible. Usages:
error: (resp) => {
console.error(resp);
throw resp;
}
error: (resp) => {
console.error(resp);
return Promise.reject(resp);
}
error: (resp) => {
console.error(resp);
return resp.text().then(text => {
throw { ...resp, errorText: text };
});
}
error: (resp) => {
console.error(resp);
return new Promise(resolve => {
// Resolve after 1 second
setTimeout(() => {
resolve({ something: {} });
}, 1000);
});
}