修改了@ehason/utils
This commit is contained in:
parent
1c0f15491e
commit
af71c348f4
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@
|
||||
/auth/.idea/
|
||||
/utils/.idea/
|
||||
/utils/node_modules/
|
||||
/test/node_modules/
|
||||
|
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "test-debug",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/test/test.js"
|
||||
}
|
||||
]
|
||||
}
|
139
utils/impl/httpstatus.js
Normal file
139
utils/impl/httpstatus.js
Normal file
@ -0,0 +1,139 @@
|
||||
const Status = {
|
||||
Continue: 100,
|
||||
SwitchingProtocols: 101,
|
||||
Processing: 102,
|
||||
EarlyHints: 103,
|
||||
|
||||
OK: 200,
|
||||
Created: 201,
|
||||
Accepted: 202,
|
||||
NonAuthoritativeInfo: 203,
|
||||
NoContent: 204,
|
||||
ResetContent: 205,
|
||||
PartialContent: 206,
|
||||
Multi: 207,
|
||||
AlreadyReported: 208,
|
||||
IMUsed: 226,
|
||||
|
||||
MultipleChoices: 300,
|
||||
MovedPermanently: 301,
|
||||
Found: 302,
|
||||
SeeOther: 303,
|
||||
NotModified: 304,
|
||||
UseProxy: 305,
|
||||
TemporaryRedirect: 307,
|
||||
PermanentRedirect: 308,
|
||||
|
||||
BadRequest: 400,
|
||||
Unauthorized: 401,
|
||||
PaymentRequired: 402,
|
||||
Forbidden: 403,
|
||||
NotFound: 404,
|
||||
MethodNotAllowed: 405,
|
||||
NotAcceptable: 406,
|
||||
ProxyAuthRequired: 407,
|
||||
RequestTimeout: 408,
|
||||
Conflict: 409,
|
||||
Gone: 410,
|
||||
LengthRequired: 411,
|
||||
PreconditionFailed: 412,
|
||||
RequestEntityTooLarge: 413,
|
||||
RequestURITooLong: 414,
|
||||
UnsupportedMediaType: 415,
|
||||
RequestedRangeNotSatisfiable: 416,
|
||||
ExpectationFailed: 417,
|
||||
Teapot: 418,
|
||||
MisdirectedRequest: 421,
|
||||
UnprocessableEntity: 422,
|
||||
Locked: 423,
|
||||
FailedDependency: 424,
|
||||
TooEarly: 425,
|
||||
UpgradeRequired: 426,
|
||||
PreconditionRequired: 428,
|
||||
TooManyRequests: 429,
|
||||
RequestHeaderFieldsTooLarge: 431,
|
||||
UnavailableForLegalReasons: 451,
|
||||
|
||||
InternalServerError: 500,
|
||||
NotImplemented: 501,
|
||||
BadGateway: 502,
|
||||
ServiceUnavailable: 503,
|
||||
GatewayTimeout: 504,
|
||||
HTTPVersionNotSupported: 505,
|
||||
VariantAlsoNegotiates: 506,
|
||||
InsufficientStorage: 507,
|
||||
LoopDetected: 508,
|
||||
NotExtended: 510,
|
||||
NetworkAuthenticationRequired: 511
|
||||
}
|
||||
|
||||
const StatusStr = {
|
||||
Continue: "Continue",
|
||||
SwitchingProtocols: "Switching Protocols",
|
||||
Processing: "Processing",
|
||||
EarlyHints: "Early Hints",
|
||||
|
||||
OK: "OK",
|
||||
Created: "Created",
|
||||
Accepted: "Accepted",
|
||||
NonAuthoritativeInfo: "Non-Authoritative Information",
|
||||
NoContent: "No Content",
|
||||
ResetContent: "Reset Content",
|
||||
PartialContent: "Partial Content",
|
||||
Multi: "Multi-",
|
||||
AlreadyReported: "Already Reported",
|
||||
IMUsed: "IM Used",
|
||||
|
||||
MultipleChoices: "Multiple Choices",
|
||||
MovedPermanently: "Moved Permanently",
|
||||
Found: "Found",
|
||||
SeeOther: "See Other",
|
||||
NotModified: "Not Modified",
|
||||
UseProxy: "Use Proxy",
|
||||
TemporaryRedirect: "Temporary Redirect",
|
||||
PermanentRedirect: "Permanent Redirect",
|
||||
|
||||
BadRequest: "Bad Request",
|
||||
Unauthorized: "Unauthorized",
|
||||
PaymentRequired: "Payment Required",
|
||||
Forbidden: "Forbidden",
|
||||
NotFound: "Not Found",
|
||||
MethodNotAllowed: "Method Not Allowed",
|
||||
NotAcceptable: "Not Acceptable",
|
||||
ProxyAuthRequired: "Proxy Authentication Required",
|
||||
RequestTimeout: "Request Timeout",
|
||||
Conflict: "Conflict",
|
||||
Gone: "Gone",
|
||||
LengthRequired: "Length Required",
|
||||
PreconditionFailed: "Precondition Failed",
|
||||
RequestEntityTooLarge: "Request Entity Too Large",
|
||||
RequestURITooLong: "Request URI Too Long",
|
||||
UnsupportedMediaType: "Unsupported Media Type",
|
||||
RequestedRangeNotSatisfiable: "Requested Range Not Satisfiable",
|
||||
ExpectationFailed: "Expectation Failed",
|
||||
Teapot: "I'm a teapot",
|
||||
MisdirectedRequest: "Misdirected Request",
|
||||
UnprocessableEntity: "Unprocessable Entity",
|
||||
Locked: "Locked",
|
||||
FailedDependency: "Failed Dependency",
|
||||
TooEarly: "Too Early",
|
||||
UpgradeRequired: "Upgrade Required",
|
||||
PreconditionRequired: "Precondition Required",
|
||||
TooManyRequests: "Too Many Requests",
|
||||
RequestHeaderFieldsTooLarge: "Request Header Fields Too Large",
|
||||
UnavailableForLegalReasons: "Unavailable For Legal Reasons",
|
||||
|
||||
InternalServerError: "Internal Server Error",
|
||||
NotImplemented: "Not Implemented",
|
||||
BadGateway: "Bad Gateway",
|
||||
ServiceUnavailable: "Service Unavailable",
|
||||
GatewayTimeout: "Gateway Timeout",
|
||||
HTTPVersionNotSupported: "HTTP Version Not Supported",
|
||||
VariantAlsoNegotiates: "Variant Also Negotiates",
|
||||
InsufficientStorage: "Insufficient Storage",
|
||||
LoopDetected: "Loop Detected",
|
||||
NotExtended: "Not Extended",
|
||||
NetworkAuthenticationRequired: "Network Authentication Required",
|
||||
}
|
||||
|
||||
module.exports = { Status, StatusStr }
|
@ -8,10 +8,10 @@ function ctxresp(ctx, data, errno, errmsg) {
|
||||
if (data === null || data === undefined) data = {};
|
||||
|
||||
ctx.body = {
|
||||
result: errno === 0 ? 'ok' : 'fail',
|
||||
error: { code: errno, msg: errmsg },
|
||||
code: errno,
|
||||
msg: errmsg,
|
||||
data: data,
|
||||
stime: Moment().format('YYYY-MM-DD HH:mm:ss')
|
||||
stime: Moment().format('YYYY-MM-DD HH:mm:ss SSS')
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,5 +2,6 @@
|
||||
module.exports = {
|
||||
prxrmq: require('./impl/prxrmq'),
|
||||
ctxresp: require('./impl/koaresp'),
|
||||
crc: require('./impl/crc')
|
||||
crc: require('./impl/crc'),
|
||||
httpstatus: require('./impl/httpstatus')
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ehason/utils",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.5",
|
||||
"description": "Utils for ehason develope",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user