Skip to content

fatcherjs/middleware-exception

Repository files navigation

@fatcherjs/middleware-exception

Install

NPM

>$ npm install @fatcherjs/middleware-exception

CDN

<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
});

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors