Commit 6c8dae2f authored by 王源's avatar 王源 🎧

修改未捕获异常返回数据格式

parent 209da1be
......@@ -38,7 +38,12 @@ class AppExceptionHandler extends ExceptionHandler
$this->stdoutLogger->error($msg);
$this->logger->error($msg);
$this->stdoutLogger->error($throwable->getTraceAsString());
return $response->withHeader("Server", "H5Q-OA")->withStatus(500)->withBody(new SwooleStream($msg));
// 格式化输出
$data = json_encode([
'code' => $throwable->getCode() ?: 400,
'msg' => $throwable->getMessage(),
], JSON_UNESCAPED_UNICODE);
return $response->withAddedHeader('content-type', 'application/json')->withBody(new SwooleStream($data));
}
public function isValid(Throwable $throwable): bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment