Tinywan / webman-exception

exception handler library for webman plugin
https://www.workerman.net/webman
MIT License
15 stars 6 forks source link

1.3.3升级1.5.0出现异常 #15

Closed bilulanlv closed 4 months ago

bilulanlv commented 4 months ago

这是我的配置文件内容 因为我的逻辑需要用到error_code,所以更改了原来默认的code=>200为'error_code'=>200 // 自定义响应消息 'body' => [ 'error_code' => 200, 'msg' => '服务器内部异常', 'data' => null ],

抛出异常 throw new UnauthorizedHttpException('Fail 1', ['errorCode' => 3001]);

v1.3.3版本正常输出 [ "error_code": 3001, "msg": "success", "data": "data" ]

下面是V1.5.0返回的内容,error_code输出的默认值 [ "error_code": 200, "msg": "success", "data": "data" ]

bilulanlv commented 4 months ago

已经pr了。 升级差点出了大问题。

bilulanlv commented 4 months ago

我看到了这个更改。https://github.com/Tinywan/webman-exception/commit/c099850609e8d983f6bc4943b626669bd2c98049 为什么只有BaseException的时候才用异常的errorCode。如果之前的业务有使用其他异常自定义errorCode,并且需要靠errorCode判断后面的逻辑,那就会全盘出问题。

bilulanlv commented 4 months ago

v1.5.0版本,如何让UnauthorizedHttpException抛出自定义的错误errorCode呢?

Tinywan commented 4 months ago

通过第二个参数数组

throw new UnauthorizedHttpException('无效的授权码', ['errorCode' => '我的自定义的错误errorCode']);
bilulanlv commented 4 months ago

从1.3.4起,这个更改已经将errorCode写死了, $bodyKey[0] ?? 'code' => $bodyValue[0] ?? 0,

通过第二个参数数组 throw new UnauthorizedHttpException('无效的授权码', ['errorCode' => 30001]); 这样只会显示,你可以自己测试一下。 { "error_code": 200, "msg": "无效的授权码", "data": {} }

Tinywan commented 4 months ago

你昨天提交的PR我看已经修复了是不