$throwable->getCode() ?: 500, 'message' => $throwable->getMessage() ?: '服务器内部错误', 'request_id' => Context::get('request_id', ''), 'timestamp' => time(), ]; // 开发环境显示堆栈信息 if (env('APP_ENV') === 'dev') { $data['trace'] = $throwable->getTraceAsString(); } $body = json_encode($data, JSON_UNESCAPED_UNICODE); return $response->withHeader('Content-Type', 'application/json') ->withStatus($data['code'] >= 400 && $data['code'] < 500 ? $data['code'] : 500) ->withBody(new SwooleStream($body)); } public function isValid(Throwable $throwable): bool { return true; } }