popsicle-status
Version:
Popsicle middleware for rejecting responses with bad HTTP statuses
21 lines • 672 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
class StatusError extends Error {
constructor(response, message) {
super(message);
this.response = response;
this.code = "EINVALIDSTATUS";
this.status = response.status;
}
}
exports.StatusError = StatusError;
function status(min = 200, max = 400) {
return async function checkStatus(req, next) {
const res = await next();
if (res.status >= min && res.status < max)
return res;
throw new StatusError(res, `${req.url} responded with ${res.status}`);
};
}
exports.status = status;
//# sourceMappingURL=index.js.map
;