@midwayjs/koa 3.0.4 → 3.0.8

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/dist/framework.js CHANGED
@@ -52,12 +52,12 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
52
52
  enumerable: true,
53
53
  });
54
54
  const onerrorConfig = this.configService.getConfiguration('onerror');
55
- (0, onerror_1.setupOnerror)(this.app, onerrorConfig, this.logger);
55
+ (0, onerror_1.setupOnError)(this.app, onerrorConfig, this.logger);
56
56
  // not found middleware
57
57
  const notFound = async (ctx, next) => {
58
58
  await next();
59
- if (!ctx._matchedRoute) {
60
- throw new core_1.httpError.NotFoundError();
59
+ if (!ctx._matchedRoute && ctx.body === undefined) {
60
+ throw new core_1.httpError.NotFoundError(`${ctx.path} Not Found`);
61
61
  }
62
62
  };
63
63
  // root middleware
@@ -3,7 +3,7 @@ import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midw
3
3
  import * as koa from 'koa';
4
4
  import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
5
5
  import { RouterParamValue } from '@midwayjs/decorator';
6
- import { CookieSetOptions } from '@midwayjs/cookies';
6
+ import { Cookies, CookieSetOptions } from '@midwayjs/cookies';
7
7
  export declare type IMidwayKoaContext = IMidwayContext<KoaContext>;
8
8
  export declare type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext, koa<DefaultState, IMidwayKoaContext> & {
9
9
  generateController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): Middleware<DefaultState, IMidwayKoaContext>;
@@ -134,6 +134,10 @@ declare module 'koa' {
134
134
  body?: any;
135
135
  rawBody: string;
136
136
  }
137
+ interface Context {
138
+ cookies: Cookies;
139
+ app: Application;
140
+ }
137
141
  }
138
142
  export {};
139
143
  //# sourceMappingURL=interface.d.ts.map
package/dist/onerror.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare function setupOnerror(app: any, config: any, logger: any): void;
1
+ export declare function setupOnError(app: any, config: any, logger: any): void;
2
2
  //# sourceMappingURL=onerror.d.ts.map
package/dist/onerror.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupOnerror = void 0;
3
+ exports.setupOnError = void 0;
4
4
  const http = require("http");
5
5
  const utils_1 = require("./utils");
6
- function setupOnerror(app, config, logger) {
6
+ const decorator_1 = require("@midwayjs/decorator");
7
+ function setupOnError(app, config, logger) {
7
8
  const errorOptions = Object.assign({
8
9
  // support customize accepts function
9
10
  accepts() {
@@ -113,7 +114,15 @@ function setupOnerror(app, config, logger) {
113
114
  (0, utils_1.sendToWormhole)(this.req);
114
115
  // wrap non-error object
115
116
  if (!(err instanceof Error)) {
116
- const newError = new Error('non-error thrown: ' + err);
117
+ let errMsg = err;
118
+ if (typeof err === 'object') {
119
+ try {
120
+ errMsg = decorator_1.Utils.safeStringify(err);
121
+ // eslint-disable-next-line no-empty
122
+ }
123
+ catch (e) { }
124
+ }
125
+ const newError = new Error('non-error thrown: ' + errMsg);
117
126
  // err maybe an object, try to copy the name, message and stack to the new error instance
118
127
  if (err) {
119
128
  if (err.name)
@@ -168,10 +177,10 @@ function setupOnerror(app, config, logger) {
168
177
  }
169
178
  }
170
179
  if (type === 'json') {
171
- this.body = JSON.stringify(this.body);
180
+ this.body = decorator_1.Utils.safeStringify(this.body);
172
181
  }
173
182
  this.res.end(this.body);
174
183
  };
175
184
  }
176
- exports.setupOnerror = setupOnerror;
185
+ exports.setupOnError = setupOnError;
177
186
  //# sourceMappingURL=onerror.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.0.4",
3
+ "version": "3.0.8",
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.4",
26
+ "@midwayjs/decorator": "^3.0.7",
27
27
  "@midwayjs/logger": "^2.15.0",
28
- "@midwayjs/mock": "^3.0.4",
28
+ "@midwayjs/mock": "^3.0.7",
29
29
  "@types/koa": "2.13.4",
30
30
  "@types/koa-router": "7.4.4",
31
31
  "fs-extra": "10.0.0"
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@koa/router": "^10.0.0",
35
35
  "@midwayjs/cookies": "1.0.1",
36
- "@midwayjs/core": "^3.0.4",
37
- "@midwayjs/session": "^3.0.4",
36
+ "@midwayjs/core": "^3.0.7",
37
+ "@midwayjs/session": "^3.0.7",
38
38
  "koa": "2.13.4",
39
39
  "koa-bodyparser": "4.3.0"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=12"
48
48
  },
49
- "gitHead": "c2a37dd026c7bf3e855f4498691f572ef61396e3"
49
+ "gitHead": "5e58d30e217ef06096cebf588e19b8ce020a3d96"
50
50
  }