0.0.46 • Published 4 years ago

letcome-env v0.0.46

Weekly downloads
183
License
-
Repository
-
Last release
4 years ago

letcome-env

Protocol

200 OK:请求成功
201 Created:已创建
204 No Content:没有实体内容相应

300 Multiple Choices:重定向
301 Moved Permanently:永久重定向
302 Found:临时重定向
304 Not Modified:可继续使用缓存

400 Bad Request:客户端错误
401 Unauthorized:未登录
402 Payment Required:需要支付
403 Forbidden:禁止操作
404 Not Found:目标不存在
405 Method Not Allowed:请求方法不被支持
406 Not Acceptable:参数不正确
408 Request Timeout:请求超时
409 Conflict:产生冲突
410 Gone:目标已消失
412 Precondition Failed:先决条件不满足
413 Request Entity Too Large:请求实体太大
415 Unsupported Media Type:服务器不支持该格式
416 Requested Range Not Satisfiable:请求范围不被满足
422 Unprocessable Entity:格式正确但语义错误
423 Locked:资源已被锁定
428 Precondition Required:要求满足一定条件
429 Too Many Requests:请求次数太多
451 Unavailable For Legal Reasons:法律要求被拒绝

500 Internal Server Error:服务器错误
501 Not Implemented:服务器不支持该功能
503 Service Unavailable:服务不可用
507 Insufficient Storage:服务器存储空间不够

Globals

_ https://github.com/lodash/lodash

ms https://github.com/zeit/ms

logger https://github.com/winstonjs/winston

router https://github.com/ZijianHe/koa-router

agenda https://github.com/agenda/agenda

arhat https://wiki.lynctone.com/

broker https://github.com/dashersw/cote

mongoose https://github.com/Automattic/mongoose

jwtoken https://github.com/auth0/node-jsonwebtoken

Example

var request = require( 'superagent-use' )( require( 'superagent' ));

request.use( request => {
    request.set( 'Authorization', 'Bearer xxxxx' );         // token 认证
    request.timeout({ response: 8000, deadline: 60000 });   // 普通请求8秒,上传下载1分钟
    if ( request.method === 'GET' ) request.retry();        // 只有 GET 请求能安全重试
});

request.use( request => {
    request.catch( err => {
        if ( err.timeout || !err.status ) console.log( '网络不太好' );
        else if ( err.status >= 500 ) console.log( '有些不对劲' );
    });
});

let req = request.get( 'https://api.letcome.net' )
    .query({ aa: 'bb' })
    .then( res => {})
    .catch( err => {
        if ( err.status >= 400 && err.status < 500 )
            console.log( `请求不合法 ${ err.status }` );    // 前端需要细化提示
    });
0.0.46

4 years ago

0.0.45

4 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago