@eggjs/onerror 3.0.0 → 3.0.1-beta.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/README.md +2 -6
- package/dist/agent.d.ts +10 -0
- package/dist/agent.js +15 -0
- package/dist/app.d.ts +16 -0
- package/dist/app.js +111 -0
- package/{src/config/config.default.ts → dist/config/config.default.d.ts} +8 -12
- package/dist/config/config.default.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/error_view.d.ts +158 -0
- package/dist/lib/error_view.js +224 -0
- package/dist/{commonjs/lib → lib}/onerror_page.mustache.html +1 -1
- package/dist/lib/utils.d.ts +10 -0
- package/dist/lib/utils.js +21 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.js +1 -0
- package/package.json +33 -55
- package/dist/commonjs/agent.d.ts +0 -6
- package/dist/commonjs/agent.js +0 -16
- package/dist/commonjs/app.d.ts +0 -12
- package/dist/commonjs/app.js +0 -150
- package/dist/commonjs/config/config.default.d.ts +0 -27
- package/dist/commonjs/config/config.default.js +0 -15
- package/dist/commonjs/index.d.ts +0 -1
- package/dist/commonjs/index.js +0 -4
- package/dist/commonjs/lib/error_view.d.ts +0 -154
- package/dist/commonjs/lib/error_view.js +0 -248
- package/dist/commonjs/lib/utils.d.ts +0 -10
- package/dist/commonjs/lib/utils.js +0 -53
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/types.d.ts +0 -7
- package/dist/commonjs/types.js +0 -3
- package/dist/esm/agent.d.ts +0 -6
- package/dist/esm/agent.js +0 -13
- package/dist/esm/app.d.ts +0 -12
- package/dist/esm/app.js +0 -144
- package/dist/esm/config/config.default.d.ts +0 -27
- package/dist/esm/config/config.default.js +0 -10
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/lib/error_view.d.ts +0 -154
- package/dist/esm/lib/error_view.js +0 -241
- package/dist/esm/lib/onerror_page.mustache.html +0 -761
- package/dist/esm/lib/utils.d.ts +0 -10
- package/dist/esm/lib/utils.js +0 -43
- package/dist/esm/package.json +0 -3
- package/dist/esm/types.d.ts +0 -7
- package/dist/esm/types.js +0 -2
- package/dist/package.json +0 -4
- package/src/agent.ts +0 -12
- package/src/app.ts +0 -160
- package/src/index.ts +0 -1
- package/src/lib/error_view.ts +0 -281
- package/src/lib/onerror_page.mustache.html +0 -761
- package/src/lib/utils.ts +0 -47
- package/src/types.ts +0 -12
- package/src/typings/index.d.ts +0 -4
package/src/lib/utils.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import type { Context, EggCore } from '@eggjs/core';
|
|
4
|
-
import type { OnerrorError } from 'koa-onerror';
|
|
5
|
-
|
|
6
|
-
export function detectErrorMessage(ctx: Context, err: OnerrorError) {
|
|
7
|
-
// detect json parse error
|
|
8
|
-
if (err.status === 400 &&
|
|
9
|
-
err.name === 'SyntaxError' &&
|
|
10
|
-
ctx.request.is('application/json', 'application/vnd.api+json', 'application/csp-report')) {
|
|
11
|
-
return 'Problems parsing JSON';
|
|
12
|
-
}
|
|
13
|
-
return err.message;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function detectStatus(err: OnerrorError) {
|
|
17
|
-
// detect status
|
|
18
|
-
let status = err.status || 500;
|
|
19
|
-
if (status < 200) {
|
|
20
|
-
// invalid status consider as 500, like urllib will return -1 status
|
|
21
|
-
status = 500;
|
|
22
|
-
}
|
|
23
|
-
return status;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function accepts(ctx: Context) {
|
|
27
|
-
if (ctx.acceptJSON) return 'json';
|
|
28
|
-
if (ctx.acceptJSONP) return 'js';
|
|
29
|
-
return 'html';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isProd(app: EggCore) {
|
|
33
|
-
return app.config.env !== 'local' && app.config.env !== 'unittest';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get the source directory name
|
|
38
|
-
*/
|
|
39
|
-
export function getSourceDirname() {
|
|
40
|
-
if (typeof __dirname === 'string') {
|
|
41
|
-
return path.dirname(__dirname);
|
|
42
|
-
}
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
46
|
-
return path.dirname(path.dirname(__filename));
|
|
47
|
-
}
|
package/src/types.ts
DELETED
package/src/typings/index.d.ts
DELETED