Skip to content

Commit

Permalink
fix: use @eggjs/onerror
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 2, 2025
1 parent b8d2d9d commit fac8735
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 48 deletions.
1 change: 0 additions & 1 deletion index-old.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
// BaseContextClass as CoreBaseContextClass,
// } from 'egg-core';
// import EggCookies = require('egg-cookies');
// import 'egg-onerror';
// import 'egg-multipart';
// import 'egg-logrotator';
// import 'egg-view';
Expand Down
46 changes: 22 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,47 @@
"egg"
],
"dependencies": {
"@eggjs/cluster": "^3.0.0",
"@eggjs/cookies": "^3.0.0",
"@eggjs/core": "^6.3.0",
"@eggjs/cluster": "^3.0.1",
"@eggjs/cookies": "^3.1.0",
"@eggjs/core": "^6.3.1",
"@eggjs/development": "^4.0.0",
"@eggjs/i18n": "^3.0.1",
"@eggjs/jsonp": "^3.0.0",
"@eggjs/onerror": "^3.0.0",
"@eggjs/schedule": "^5.0.2",
"@eggjs/security": "^4.0.0",
"@eggjs/session": "^4.0.0",
"@eggjs/session": "^4.0.1",
"@eggjs/static": "^3.0.0",
"@eggjs/utils": "^4.2.4",
"@eggjs/watcher": "^4.0.3",
"@eggjs/utils": "^4.2.5",
"@eggjs/watcher": "^4.0.4",
"circular-json-for-egg": "^1.0.0",
"cluster-client": "^3.7.0",
"egg-errors": "^2.3.1",
"egg-logger": "^3.6.0",
"egg-logrotator": "^3.1.0",
"egg-multipart": "^3.1.0",
"egg-onerror": "^2.1.1",
"egg-view": "^2.1.3",
"egg-errors": "^2.3.2",
"egg-logger": "^3.6.1",
"egg-logrotator": "^3.2.0",
"egg-multipart": "^3.5.0",
"egg-view": "^2.1.4",
"extend2": "^4.0.0",
"graceful": "^2.0.0",
"humanize-ms": "^2.0.0",
"is-type-of": "^2.1.0",
"is-type-of": "^2.2.0",
"koa-bodyparser": "^4.4.1",
"koa-override": "^4.0.0",
"onelogger": "^1.0.1",
"performance-ms": "^1.1.0",
"sendmessage": "^3.0.1",
"urllib": "^4.6.11",
"utility": "^2.1.0",
"ylru": "^1.3.2"
"utility": "^2.5.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/bin": "^7.0.0",
"@eggjs/koa": "^2.19.1",
"@arethetypeswrong/cli": "^0.17.3",
"@eggjs/bin": "^7.0.2",
"@eggjs/koa": "^2.20.6",
"@eggjs/mock": "^6.0.5",
"@eggjs/supertest": "^8.1.1",
"@eggjs/supertest": "^8.2.0",
"@eggjs/tsconfig": "1",
"@types/koa-bodyparser": "^4.3.12",
"@types/mocha": "^10.0.7",
"@types/ms": "^0.7.34",
"@types/mocha": "^10.0.10",
"@types/node": "22",
"address": "2",
"assert-file": "1",
Expand All @@ -75,12 +73,12 @@
"eslint-config-egg": "14",
"formstream": "^1.5.1",
"koa-static": "^5.0.0",
"mm": "^3.4.0",
"mm": "^4.0.2",
"pedding": "^2.0.1",
"prettier": "^2.7.1",
"prettier": "^3.4.2",
"rimraf": "6",
"runscript": "^2.0.1",
"sdk-base": "^4.2.1",
"sdk-base": "^5.0.1",
"spy": "^1.0.0",
"tsd": "^0.31.2",
"tshy": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion site/docs/basics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).
## Plugin List

- Framework has default built-in plugins for enterprise applications [Common plugins](https://eggjs.org/zh-cn/plugins/):
  - [onerror](https://github.com/eggjs/egg-onerror) Uniform Exception Handling
  - [onerror](https://github.com/eggjs/onerror) Uniform Exception Handling
  - [session](https://github.com/eggjs/session) Session implementation
  - [i18n](https://github.com/eggjs/i18n) Multilingual
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring
Expand Down
2 changes: 1 addition & 1 deletion site/docs/basics/plugin.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ exports.mysql = {
## 插件列表

- 框架默认内置了企业级应用[常用的插件](https://eggjs.org/zh-cn/plugins/)
- [onerror](https://github.com/eggjs/egg-onerror) 统一异常处理
- [onerror](https://github.com/eggjs/onerror) 统一异常处理
- [session](https://github.com/eggjs/session) Session 实现
- [i18n](https://github.com/eggjs/i18n) 多语言
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控
Expand Down
12 changes: 6 additions & 6 deletions site/docs/core/cookie-and-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ module.exports = (app) => {
```

The implementation of `sessionStore` can also be encapsulated into a plugin.
For example, [egg-session-redis] stores Session in Redis.
To apply it, import [egg-redis] and [egg-session-redis] plugin in your application.
For example, [@eggjs/session-redis] stores Session in Redis.
To apply it, import [@eggjs/redis] and [@eggjs/session-redis] plugin in your application.

```js
// plugin.js
exports.redis = {
enable: true,
package: 'egg-redis',
package: '@eggjs/redis',
};
exports.sessionRedis = {
enable: true,
package: 'egg-session-redis',
package: '@eggjs/session-redis',
};
```

Expand Down Expand Up @@ -283,5 +283,5 @@ module.exports = {
};
```

[egg-redis]: https://github.com/eggjs/egg-redis
[egg-session-redis]: https://github.com/eggjs/egg-session-redis
[@eggjs/redis]: https://github.com/eggjs/redis
[@eggjs/session-redis]: https://github.com/eggjs/session-redis
9 changes: 3 additions & 6 deletions site/docs/core/cookie-and-session.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ module.exports = app => {
};
```

例如,通过引入 [egg-redis](https://github.com/eggjs/egg-redis)[egg-session-redis](https://github.com/eggjs/egg-session-redis) 插件,可以将 Session 存储到 redis 中。
例如,通过引入 [@eggjs/redis](https://github.com/eggjs/redis)[@eggjs/session-redis](https://github.com/eggjs/session-redis) 插件,可以将 Session 存储到 redis 中。

```js
// plugin.js
exports.redis = {
enable: true,
package: 'egg-redis',
package: '@eggjs/redis',
};
exports.sessionRedis = {
enable: true,
package: 'egg-session-redis',
package: '@eggjs/session-redis',
};
```

Expand Down Expand Up @@ -231,6 +231,3 @@ exports.session = {
renew: true,
};
```

[egg-redis]: https://github.com/eggjs/egg-redis
[egg-session-redis]: https://github.com/eggjs/egg-session-redis
2 changes: 1 addition & 1 deletion site/docs/core/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ For convenience of locating problems, exceptions must be guaranteed to be Error

## Egg Takes Charge of Exceptions

[egg-onerror](https://github.com/eggjs/egg-onerror), one of Egg's plugin, handles all exceptions thrown in Middleware, Controller and Service, and returns the error as response based on "Accept" in request header field.
[@eggjs/onerror](https://github.com/eggjs/onerror), one of Egg's plugin, handles all exceptions thrown in Middleware, Controller and Service, and returns the error as response based on "Accept" in request header field.

| Accept | ENV | errorPageUrl | response |
| ------------ | ---------------- | ------------ | ---------------------------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion site/docs/core/error-handling.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HomeController extends Controller {

## 框架层统一异常处理

框架通过 [onerror](https://github.com/eggjs/egg-onerror) 插件提供统一的错误处理机制。此机制将捕获所有处理方法(Middleware、Controller、Service)中抛出的任何异常,并根据请求预期的响应类型返回不同的错误内容。
框架通过 [@eggjs/onerror](https://github.com/eggjs/onerror) 插件提供统一的错误处理机制。此机制将捕获所有处理方法(Middleware、Controller、Service)中抛出的任何异常,并根据请求预期的响应类型返回不同的错误内容。

| 请求格式需求 | 环境 | `errorPageUrl` 配置 | 返回内容 |
| ------------ | ---- | ------------------- | -------- |
Expand Down
2 changes: 1 addition & 1 deletion site/docs/tutorials/socketio.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.io = {
> Here `redis` is only used to store connection instance information, see [# server.adapter](https://socket.io/docs/server-api/#server-adapter-value)
**Note:**
If the project also uses the `egg-redis`, please configure it separately. Do not share it.
If the project also uses the `@eggjs/redis`, please configure it separately. Do not share it.

### Deployment

Expand Down
2 changes: 1 addition & 1 deletion site/docs/tutorials/socketio.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.io = {
> 开启 `redis` 后,程序在启动时会尝试连接到 redis 服务器。此处的 `redis` 仅用于存储连接实例信息,详见 [#server.adapter](https://socket.io/docs/server-api/#server-adapter-value)
**注意:**
如果项目中同时使用了 `egg-redis`,请分别配置,不可共用。
如果项目中同时使用了 `@eggjs/redis`,请分别配置,不可共用。

### 部署

Expand Down
2 changes: 1 addition & 1 deletion src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
*/
onerror: {
enable: true,
package: 'egg-onerror',
package: '@eggjs/onerror',
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '@eggjs/static';
import '@eggjs/security';
import '@eggjs/schedule';
import '@eggjs/session';

import '@eggjs/onerror';
export type {
EggAppInfo,
} from '@eggjs/core';
Expand Down
7 changes: 6 additions & 1 deletion test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ expectType<string>(app.config.security.csrf.headerName);
// session plugin types
expectType<boolean>(app.config.session.httpOnly);

// onerror plugin types
expectType<(err: any, ctx: any) => void>(app.config.onerror.html!);
expectType<string>(app.config.onerror.errorPageUrl as string);

class AppBoot implements ILifecycleBoot {
private readonly app: Application;

Expand Down Expand Up @@ -103,7 +107,8 @@ class AppBoot implements ILifecycleBoot {
}
}

const appBoot = new AppBoot(app);
const app1 = {} as Application;
const appBoot = new AppBoot(app1);
expectType<IBoot>(appBoot);
expectType<ILifecycleBoot>(appBoot);

Expand Down
4 changes: 2 additions & 2 deletions test/lib/core/loader/load_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('test/lib/core/loader/load_plugin.test.ts', () => {
from: path.join(baseDir, 'config/plugin.js'),
});
assert.equal(
appLoader.plugins.onerror.path, path.join(EGG_BASE, 'node_modules/egg-onerror'),
appLoader.plugins.onerror.path, path.join(EGG_BASE, 'node_modules/@eggjs/onerror/dist/esm'),
);
assert(appLoader.plugins.onerror.package === 'egg-onerror');
assert.equal(appLoader.plugins.onerror.package, '@eggjs/onerror');
assert.match(appLoader.plugins.onerror.version!, /\d+\.\d+\.\d+/);
assert(Array.isArray(appLoader.orderPlugins));
});
Expand Down

0 comments on commit fac8735

Please sign in to comment.