promise-success
v2.0.3
Published
this is a encapsulation based on urllib, it only call Fulfilled when the status === 200
Downloads
5
Maintainers
Readme
promise-success
目标:封装公司现有请求:
请求返回200:resolve,附带经过JSON.parse()后的数据。
其他情况一律:reject,并附带JSON.parse()后的数据(如果有的话)和请求的 statusCode。
Install
$ npm install promise-success --save
Usage
'use strict';
var koa = require('koa');
var app = koa();
var request = require('promise-success');
app.use(function *(){
try {
var result = yield request('https://www.baidu.com');
this.body = result;
} catch (e) {
this.body = e;
}
});
app.listen(8000);