项目作者: codesuki

项目描述 :
Add functions that will be called during end() e.g. for handling error conditions without having the same code all over the place.
高级语言: JavaScript
项目地址: git://github.com/codesuki/superagent-intercept.git
创建时间: 2015-03-04T06:41:23Z
项目社区:https://github.com/codesuki/superagent-intercept

开源协议:MIT License

下载


superagent-intercept

Add interceptors that will be called during end() e.g. for handling error conditions without having the same code all over the place.

Support

Please consider supporting the project by starring it on GitHub :)

https://github.com/codesuki/superagent-intercept

Install

  1. npm install superagent-intercept

Example

  1. let AuthIntercept = require('superagent-intercept')((err, res) => {
  2. if (res.status == 401) {
  3. // route to login
  4. }
  5. });
  6. request.get('/api/something/' + someId).use(AuthIntercept).end((err, res) {
  7. // AuthIntercept will be called here.
  8. // ... code ...
  9. });