@midwayjs/koa 3.0.0-beta.11 → 3.0.0-beta.12
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/CHANGELOG.md +12 -0
- package/dist/framework.d.ts +1 -1
- package/dist/framework.js +25 -1
- package/dist/interface.d.ts +1 -1
- package/dist/onerror.d.ts +2 -0
- package/dist/onerror.js +5 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +14 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
|
|
12
|
+
* support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @midwayjs/koa
|
package/dist/framework.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplicat
|
|
|
17
17
|
* @deprecated
|
|
18
18
|
* @param middlewareId
|
|
19
19
|
*/
|
|
20
|
-
generateMiddleware(middlewareId:
|
|
20
|
+
generateMiddleware(middlewareId: any): Promise<Middleware<DefaultState, IMidwayKoaContext, any>>;
|
|
21
21
|
run(): Promise<void>;
|
|
22
22
|
beforeStop(): Promise<void>;
|
|
23
23
|
getFrameworkType(): MidwayFrameworkType;
|
package/dist/framework.js
CHANGED
|
@@ -13,6 +13,7 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
13
13
|
const Router = require("@koa/router");
|
|
14
14
|
const koa = require("koa");
|
|
15
15
|
const onerror = require("koa-onerror");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
16
17
|
const COOKIES = Symbol('context#cookies');
|
|
17
18
|
class KoaControllerGenerator extends core_1.WebControllerGenerator {
|
|
18
19
|
constructor(app) {
|
|
@@ -52,6 +53,29 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
52
53
|
enumerable: true,
|
|
53
54
|
});
|
|
54
55
|
const onerrorConfig = this.configService.getConfiguration('onerror');
|
|
56
|
+
this.app.on('error', (err, ctx) => {
|
|
57
|
+
ctx = ctx || this.app.createAnonymousContext();
|
|
58
|
+
const status = (0, utils_1.detectStatus)(err);
|
|
59
|
+
// 5xx
|
|
60
|
+
if (status >= 500) {
|
|
61
|
+
try {
|
|
62
|
+
ctx.logger.error(err);
|
|
63
|
+
}
|
|
64
|
+
catch (ex) {
|
|
65
|
+
this.logger.error(err);
|
|
66
|
+
this.logger.error(ex);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// 4xx
|
|
71
|
+
try {
|
|
72
|
+
ctx.logger.warn(err);
|
|
73
|
+
}
|
|
74
|
+
catch (ex) {
|
|
75
|
+
this.logger.warn(err);
|
|
76
|
+
this.logger.error(ex);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
55
79
|
onerror(this.app, onerrorConfig);
|
|
56
80
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
57
81
|
this.app.createAnonymousContext(ctx);
|
|
@@ -118,7 +142,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
118
142
|
const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
|
|
119
143
|
if (customPort) {
|
|
120
144
|
new Promise(resolve => {
|
|
121
|
-
const args = [
|
|
145
|
+
const args = [customPort];
|
|
122
146
|
if (this.configurationOptions.hostname) {
|
|
123
147
|
args.push(this.configurationOptions.hostname);
|
|
124
148
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext
|
|
|
13
13
|
* @deprecated
|
|
14
14
|
* @param middlewareId
|
|
15
15
|
*/
|
|
16
|
-
generateMiddleware(middlewareId:
|
|
16
|
+
generateMiddleware(middlewareId: any): Promise<Middleware<DefaultState, IMidwayKoaContext>>;
|
|
17
17
|
}>;
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated use NextFunction definition
|
package/dist/onerror.js
ADDED
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectStatus = void 0;
|
|
4
|
+
function detectStatus(err) {
|
|
5
|
+
// detect status
|
|
6
|
+
let status = err.status || 500;
|
|
7
|
+
if (status < 200) {
|
|
8
|
+
// invalid status consider as 500, like urllib will return -1 status
|
|
9
|
+
status = 500;
|
|
10
|
+
}
|
|
11
|
+
return status;
|
|
12
|
+
}
|
|
13
|
+
exports.detectStatus = detectStatus;
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.12",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@midwayjs/decorator": "^3.0.0-beta.
|
|
27
|
-
"@midwayjs/logger": "^3.0.0-beta.
|
|
28
|
-
"@midwayjs/mock": "^3.0.0-beta.
|
|
26
|
+
"@midwayjs/decorator": "^3.0.0-beta.12",
|
|
27
|
+
"@midwayjs/logger": "^3.0.0-beta.12",
|
|
28
|
+
"@midwayjs/mock": "^3.0.0-beta.12",
|
|
29
29
|
"@types/koa": "^2.11.4",
|
|
30
30
|
"@types/koa-bodyparser": "^4.3.4",
|
|
31
31
|
"@types/koa-router": "^7.4.1",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@koa/router": "^10.0.0",
|
|
36
36
|
"@midwayjs/cookies": "^1.0.1",
|
|
37
|
-
"@midwayjs/core": "^3.0.0-beta.
|
|
38
|
-
"@midwayjs/session": "^3.0.0-beta.
|
|
37
|
+
"@midwayjs/core": "^3.0.0-beta.12",
|
|
38
|
+
"@midwayjs/session": "^3.0.0-beta.12",
|
|
39
39
|
"koa": "^2.13.4",
|
|
40
40
|
"koa-bodyparser": "^4.3.0",
|
|
41
41
|
"koa-onerror": "^4.1.0"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=12"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
|
|
52
52
|
}
|