@jayfong/x-server 2.77.0 → 2.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_cjs/cli/cli.js +0 -0
- package/lib/_cjs/core/handler.js +17 -1
- package/lib/core/handler.js +18 -2
- package/package.json +1 -1
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -4,6 +4,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.Handler = void 0;
|
|
7
|
+
var _got = require("got");
|
|
7
8
|
var _lzString = _interopRequireDefault(require("lz-string"));
|
|
8
9
|
var _vtils = require("vtils");
|
|
9
10
|
var vae = _interopRequireWildcard(require("vtils/vae"));
|
|
@@ -108,7 +109,22 @@ class Handler {
|
|
|
108
109
|
if (_http_error.HttpError.isHttpError(err)) {
|
|
109
110
|
throw err;
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
+
// 网络错误
|
|
113
|
+
if (err instanceof _got.HTTPError) {
|
|
114
|
+
console.error('网络请求错误', {
|
|
115
|
+
error: `${err.code || ''}:${err.name || ''}:${err.message || ''}`,
|
|
116
|
+
response: err.options.responseType !== 'buffer' ? (0, _vtils.toSingleLineString)(String(err.response.body), 50) : '',
|
|
117
|
+
method: err.options.method,
|
|
118
|
+
url: err.options.url,
|
|
119
|
+
headers: JSON.stringify(err.options.headers || {}),
|
|
120
|
+
query: (err.options.search ?? err.options.searchParams?.toString()) || '',
|
|
121
|
+
body: err.options.body?.toString() ?? (err.options.form ? JSON.stringify(err.options.form) : '')
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// 服务器错误
|
|
125
|
+
else {
|
|
126
|
+
console.error('服务器错误', err);
|
|
127
|
+
}
|
|
112
128
|
throw new _http_error.HttpError.InternalServerError('服务异常,请稍后再试');
|
|
113
129
|
}
|
|
114
130
|
};
|
package/lib/core/handler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HTTPError as GotError } from 'got';
|
|
1
2
|
import LZString from 'lz-string';
|
|
2
|
-
import { DataPacker, base64UrlEncode, rot13 } from 'vtils';
|
|
3
|
+
import { DataPacker, base64UrlEncode, rot13, toSingleLineString } from 'vtils';
|
|
3
4
|
import * as vae from 'vtils/vae';
|
|
4
5
|
import { getZhCN, yup } from 'vtils/validator';
|
|
5
6
|
import { HttpError } from "../core/http_error";
|
|
@@ -102,7 +103,22 @@ export class Handler {
|
|
|
102
103
|
if (HttpError.isHttpError(err)) {
|
|
103
104
|
throw err;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
// 网络错误
|
|
107
|
+
if (err instanceof GotError) {
|
|
108
|
+
console.error('网络请求错误', {
|
|
109
|
+
error: `${err.code || ''}:${err.name || ''}:${err.message || ''}`,
|
|
110
|
+
response: err.options.responseType !== 'buffer' ? toSingleLineString(String(err.response.body), 50) : '',
|
|
111
|
+
method: err.options.method,
|
|
112
|
+
url: err.options.url,
|
|
113
|
+
headers: JSON.stringify(err.options.headers || {}),
|
|
114
|
+
query: (err.options.search ?? err.options.searchParams?.toString()) || '',
|
|
115
|
+
body: err.options.body?.toString() ?? (err.options.form ? JSON.stringify(err.options.form) : '')
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// 服务器错误
|
|
119
|
+
else {
|
|
120
|
+
console.error('服务器错误', err);
|
|
121
|
+
}
|
|
106
122
|
throw new HttpError.InternalServerError('服务异常,请稍后再试');
|
|
107
123
|
}
|
|
108
124
|
};
|