there are some Object exports which all extends Error, they have the same property all type
and the value are as the same as the object's name,
e.g.
var err = new ApiRequestError('err message');
console.log(err.type);
console.log(err.message);
// ApiRequestError
// err message
-
ApiRequestError
-
DBError
-
PageError
it has the
status
property which stands for httpStatus, the same as http status code, default500
var err = new PageError('err message', 404); console.log(err.staus); console.log(err.message); // 404 // err message
-
CodeException
the util for handle files
-
check the path exits?
uri
: the path (string)return true or false
-
write something into the file
uri
: the file path (string)content
: the file content (string) -
read file content
uri
: the file path (string)def
: if readfile fail or file unexits (string)return string
-
remove file
uri
: the file path (string) -
read the json file content and return a json object
uri
: the file path (string)def
: the default return when the reading fail (object) -
mkdir
dirname
: dirname
the module for http request which extend request
https://github.com/request/request/blob/master/README.md
-
the request with
get
methodurl
: request URLparams
: request paramsheader
: request header, default{}
return promise
-
the request with
get
methodurl
: request URLparams
: request paramsheader
: request header, default{}
return promise
there are some method you can register to global
// 注册请求前事件
http.onBeforeSend = function (req) {}
// 格式化输出
http.responseFormat = function (res) { return res; }
// 判断请求是否成功
http.isSuccess = function(res) { return Number(res.code) === 1; }
// 注册请求完成事件, 无论成功与否
http.onComplete = function(response) {}
// 业务上的错误回调
http.errCallback = function(response, body) {}
http.defaultOptions = {
time: true
};
//option 结构参考 https://github.com/request/request/blob/master/README.md
use:
var logger = require('koa-core').logger;
logger.log('success','http')
-
add logs content
msg
: logs content (string)type
: log type which from your conf, defaultlog
(string)
there are some method you can register to global
logger.formatMsg = function(msg, type) { }
- the only arg was the option the can see https://github.com/node-modules/mini-logger#options
the helper for view engin
-
- options default was { jsonFileName: 'staticAsset.json' }
-
get css url from the webpack asset.json file by moduleName
-
get js url from the webpack asset.json file by moduleName
-
...
-
...
-
format the date to
周x