Skip to content

Commit 762e301

Browse files
authored
fix: use @eggjs/onerror (#5389)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated dependency versions and plugin configurations for enhanced system stability and compatibility. - **Documentation** - Revised guides across multi-process handling, session management, error handling, and Socket.IO with corrected links and updated package names. - **Refactor** - Modernized asynchronous patterns and restructured lifecycle methods for better reliability. - **New Features** - Enhanced framework communication by introducing improved messaging capabilities. - Introduced a new read-only property for better access to messaging functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b8d2d9d commit 762e301

22 files changed

+134
-135
lines changed

index-old.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
// BaseContextClass as CoreBaseContextClass,
3333
// } from 'egg-core';
3434
// import EggCookies = require('egg-cookies');
35-
// import 'egg-onerror';
3635
// import 'egg-multipart';
3736
// import 'egg-logrotator';
3837
// import 'egg-view';

package.json

+22-24
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,47 @@
1919
"egg"
2020
],
2121
"dependencies": {
22-
"@eggjs/cluster": "^3.0.0",
23-
"@eggjs/cookies": "^3.0.0",
24-
"@eggjs/core": "^6.3.0",
22+
"@eggjs/cluster": "^3.0.1",
23+
"@eggjs/cookies": "^3.1.0",
24+
"@eggjs/core": "^6.3.1",
2525
"@eggjs/development": "^4.0.0",
2626
"@eggjs/i18n": "^3.0.1",
2727
"@eggjs/jsonp": "^3.0.0",
28+
"@eggjs/onerror": "^3.0.0",
2829
"@eggjs/schedule": "^5.0.2",
2930
"@eggjs/security": "^4.0.0",
30-
"@eggjs/session": "^4.0.0",
31+
"@eggjs/session": "^4.0.1",
3132
"@eggjs/static": "^3.0.0",
32-
"@eggjs/utils": "^4.2.4",
33-
"@eggjs/watcher": "^4.0.3",
33+
"@eggjs/utils": "^4.2.5",
34+
"@eggjs/watcher": "^4.0.4",
3435
"circular-json-for-egg": "^1.0.0",
3536
"cluster-client": "^3.7.0",
36-
"egg-errors": "^2.3.1",
37-
"egg-logger": "^3.6.0",
38-
"egg-logrotator": "^3.1.0",
39-
"egg-multipart": "^3.1.0",
40-
"egg-onerror": "^2.1.1",
41-
"egg-view": "^2.1.3",
37+
"egg-errors": "^2.3.2",
38+
"egg-logger": "^3.6.1",
39+
"egg-logrotator": "^3.2.0",
40+
"egg-multipart": "^3.5.0",
41+
"egg-view": "^2.1.4",
4242
"extend2": "^4.0.0",
4343
"graceful": "^2.0.0",
4444
"humanize-ms": "^2.0.0",
45-
"is-type-of": "^2.1.0",
45+
"is-type-of": "^2.2.0",
4646
"koa-bodyparser": "^4.4.1",
4747
"koa-override": "^4.0.0",
4848
"onelogger": "^1.0.1",
4949
"performance-ms": "^1.1.0",
5050
"sendmessage": "^3.0.1",
5151
"urllib": "^4.6.11",
52-
"utility": "^2.1.0",
53-
"ylru": "^1.3.2"
52+
"utility": "^2.5.0"
5453
},
5554
"devDependencies": {
56-
"@arethetypeswrong/cli": "^0.17.1",
57-
"@eggjs/bin": "^7.0.0",
58-
"@eggjs/koa": "^2.19.1",
55+
"@arethetypeswrong/cli": "^0.17.3",
56+
"@eggjs/bin": "^7.0.2",
57+
"@eggjs/koa": "^2.20.6",
5958
"@eggjs/mock": "^6.0.5",
60-
"@eggjs/supertest": "^8.1.1",
59+
"@eggjs/supertest": "^8.2.0",
6160
"@eggjs/tsconfig": "1",
6261
"@types/koa-bodyparser": "^4.3.12",
63-
"@types/mocha": "^10.0.7",
64-
"@types/ms": "^0.7.34",
62+
"@types/mocha": "^10.0.10",
6563
"@types/node": "22",
6664
"address": "2",
6765
"assert-file": "1",
@@ -75,12 +73,12 @@
7573
"eslint-config-egg": "14",
7674
"formstream": "^1.5.1",
7775
"koa-static": "^5.0.0",
78-
"mm": "^3.4.0",
76+
"mm": "^4.0.2",
7977
"pedding": "^2.0.1",
80-
"prettier": "^2.7.1",
78+
"prettier": "^3.4.2",
8179
"rimraf": "6",
8280
"runscript": "^2.0.1",
83-
"sdk-base": "^4.2.1",
81+
"sdk-base": "^5.0.1",
8482
"spy": "^1.0.0",
8583
"tsd": "^0.31.2",
8684
"tshy": "^3.0.2",

site/docs/advanced/cluster-client.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ We abstract the client interface into the following two broad categories, which
7070
Client example
7171

7272
```js
73-
const Base = require('sdk-base');
73+
const { Base } = require('sdk-base');
7474

7575
class Client extends Base {
7676
constructor(options) {
@@ -168,8 +168,8 @@ In the following I will use a simple example to introduce how to make a client s
168168

169169
```js
170170
// registry_client.js
171-
const URL = require('url');
172-
const Base = require('sdk-base');
171+
const { parse } = require('node:url');
172+
const { Base } = require('sdk-base');
173173

174174
class RegistryClient extends Base {
175175
constructor(options) {
@@ -236,7 +236,7 @@ class RegistryClient extends Base {
236236
if (changed) {
237237
this.emit(
238238
key,
239-
this._registered.get(key).map((url) => URL.parse(url, true)),
239+
this._registered.get(key).map((url) => parse(url, true)),
240240
);
241241
}
242242
}

site/docs/advanced/cluster-client.zh-CN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ win / +------------------+ \ lose
6969
客户端示例
7070

7171
```js
72-
const Base = require('sdk-base');
72+
const { Base } = require('sdk-base');
7373

7474
class Client extends Base {
7575
constructor(options) {
@@ -165,8 +165,8 @@ Leader 和 Follower 通过下面的协议进行数据交换:
165165

166166
```js
167167
// registry_client.js
168-
const URL = require('url');
169-
const Base = require('sdk-base');
168+
const { parse } = require('node:url');
169+
const { Base } = require('sdk-base');
170170

171171
class RegistryClient extends Base {
172172
constructor(options) {
@@ -233,7 +233,7 @@ class RegistryClient extends Base {
233233
if (changed) {
234234
this.emit(
235235
key,
236-
this._registered.get(key).map(url => URL.parse(url, true)),
236+
this._registered.get(key).map(url => parse(url, true)),
237237
);
238238
}
239239
}
@@ -554,4 +554,4 @@ class APIClient extends APIClientBase {
554554
}
555555

556556
module.exports = APIClient;
557-
```
557+
```

site/docs/basics/plugin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).
160160
## Plugin List
161161

162162
- Framework has default built-in plugins for enterprise applications [Common plugins](https://eggjs.org/zh-cn/plugins/):
163-
  - [onerror](https://github.com/eggjs/egg-onerror) Uniform Exception Handling
163+
  - [onerror](https://github.com/eggjs/onerror) Uniform Exception Handling
164164
  - [session](https://github.com/eggjs/session) Session implementation
165165
  - [i18n](https://github.com/eggjs/i18n) Multilingual
166166
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring

site/docs/basics/plugin.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ exports.mysql = {
160160
## 插件列表
161161

162162
- 框架默认内置了企业级应用[常用的插件](https://eggjs.org/zh-cn/plugins/)
163-
- [onerror](https://github.com/eggjs/egg-onerror) 统一异常处理
163+
- [onerror](https://github.com/eggjs/onerror) 统一异常处理
164164
- [session](https://github.com/eggjs/session) Session 实现
165165
- [i18n](https://github.com/eggjs/i18n) 多语言
166166
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控

site/docs/core/cookie-and-session.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,18 @@ module.exports = (app) => {
220220
```
221221

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

226226
```js
227227
// plugin.js
228228
exports.redis = {
229229
enable: true,
230-
package: 'egg-redis',
230+
package: '@eggjs/redis',
231231
};
232232
exports.sessionRedis = {
233233
enable: true,
234-
package: 'egg-session-redis',
234+
package: '@eggjs/session-redis',
235235
};
236236
```
237237

@@ -283,5 +283,5 @@ module.exports = {
283283
};
284284
```
285285

286-
[egg-redis]: https://github.com/eggjs/egg-redis
287-
[egg-session-redis]: https://github.com/eggjs/egg-session-redis
286+
[@eggjs/redis]: https://github.com/eggjs/redis
287+
[@eggjs/session-redis]: https://github.com/eggjs/session-redis

site/docs/core/cookie-and-session.zh-CN.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ module.exports = app => {
183183
};
184184
```
185185

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

188188
```js
189189
// plugin.js
190190
exports.redis = {
191191
enable: true,
192-
package: 'egg-redis',
192+
package: '@eggjs/redis',
193193
};
194194
exports.sessionRedis = {
195195
enable: true,
196-
package: 'egg-session-redis',
196+
package: '@eggjs/session-redis',
197197
};
198198
```
199199

@@ -231,6 +231,3 @@ exports.session = {
231231
renew: true,
232232
};
233233
```
234-
235-
[egg-redis]: https://github.com/eggjs/egg-redis
236-
[egg-session-redis]: https://github.com/eggjs/egg-session-redis

site/docs/core/error-handling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ For convenience of locating problems, exceptions must be guaranteed to be Error
6161

6262
## Egg Takes Charge of Exceptions
6363

64-
[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.
64+
[@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.
6565

6666
| Accept | ENV | errorPageUrl | response |
6767
| ------------ | ---------------- | ------------ | ---------------------------------------------------- |

site/docs/core/error-handling.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class HomeController extends Controller {
5959

6060
## 框架层统一异常处理
6161

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

6464
| 请求格式需求 | 环境 | `errorPageUrl` 配置 | 返回内容 |
6565
| ------------ | ---- | ------------------- | -------- |

site/docs/tutorials/socketio.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports.io = {
8484
> Here `redis` is only used to store connection instance information, see [# server.adapter](https://socket.io/docs/server-api/#server-adapter-value)
8585
8686
**Note:**
87-
If the project also uses the `egg-redis`, please configure it separately. Do not share it.
87+
If the project also uses the `@eggjs/redis`, please configure it separately. Do not share it.
8888

8989
### Deployment
9090

site/docs/tutorials/socketio.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports.io = {
8484
> 开启 `redis` 后,程序在启动时会尝试连接到 redis 服务器。此处的 `redis` 仅用于存储连接实例信息,详见 [#server.adapter](https://socket.io/docs/server-api/#server-adapter-value)
8585
8686
**注意:**
87-
如果项目中同时使用了 `egg-redis`,请分别配置,不可共用。
87+
如果项目中同时使用了 `@eggjs/redis`,请分别配置,不可共用。
8888

8989
### 部署
9090

src/config/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
*/
77
onerror: {
88
enable: true,
9-
package: 'egg-onerror',
9+
package: '@eggjs/onerror',
1010
},
1111

1212
/**

src/lib/egg.ts

+2
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,13 @@ declare module '@eggjs/core' {
690690
get currentContext(): EggContext | undefined;
691691
ctxStorage: AsyncLocalStorage<EggContext>;
692692
getLogger(name: string): EggLogger;
693+
get loggers(): EggLoggers;
693694
createHttpClient(options?: HttpClientOptions): HttpClient;
694695
HttpClient: typeof HttpClient;
695696
get httpClient(): HttpClient;
696697
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
697698
createAnonymousContext(req?: any): EggContext;
698699
runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>, req?: unknown): Promise<void>;
700+
readonly messenger: IMessenger;
699701
}
700702
}

src/lib/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import '@eggjs/static';
2525
import '@eggjs/security';
2626
import '@eggjs/schedule';
2727
import '@eggjs/session';
28-
28+
import '@eggjs/onerror';
2929
export type {
3030
EggAppInfo,
3131
} from '@eggjs/core';

0 commit comments

Comments
 (0)