@fatcherjs/middleware-exception
v3.0.0
Published
<div align="center"> <a href="https://codecov.io/github/fatcherjs/middleware-exception" > <img src="https://codecov.io/github/fatcherjs/middleware-exception/graph/badge.svg?token=X6W3TO6BE1"/> </a> <a href="https://www.jsdelivr.com/package/npm/
Readme
@fatcherjs/middleware-exception
Install
NPM
>$ npm install @fatcherjs/middleware-exceptionCDN
<script src="https://cdn.jsdelivr.net/npm/fatcher/dist/fatcher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-exception/dist/index.min.js"></script>
<script>
Fatcher.fatcher('url', {
middlewares: [FatcherMiddlewareException],
})
.then(response => {
console.log(response);
})
.catch(err => {
if (FatcherMiddlewareException.isFatcherError(err)) {
// http error
return;
}
// other
});
</script>Usage
import { fatcher } from 'fatcher';
import { isFatcherError, exception } from '@fatcherjs/middleware-exception';
fatcher('https://foo.bar', { middlewares: [exception] }).catch(error => {
if (isFatcherError(error)) {
// handle fatcher error
return;
}
// handle other error
});options
validateCode
import { fatcher } from 'fatcher';
import { isFatcherError, exception } from '@fatcherjs/middleware-exception';
fatcher('https://foo.bar', {
middlewares: [exception],
// throw FatcherError when status is not 200
validateCode: status => status === 200,
}).catch(error => {
if (isFatcherError(error)) {
// handle fatcher error
return;
}
// handle other error
});