getCode(); $message = $throwable->getMessage(); $data = $throwable->getData(); } else { // 其他异常 $code = $throwable->getCode(); // ErrorCode::SYSTEM_ERROR; $data = env('APP_ENV') === 'dev' ? [ 'trace' => $throwable->getTraceAsString(), 'file' => $throwable->getFile(), 'line' => $throwable->getLine(), ] : []; $message = env('APP_ENV') === 'dev' ? $throwable->getMessage() : ErrorCode::getMessage($code); } $result = [ Config::RESPONSE_FIELD_KEY_CODE => $code, Config::RESPONSE_FIELD_KEY_DATA => $data, Config::RESPONSE_FIELD_KEY_MESSAGE => $message, ]; $body = new SwooleStream(json_encode($result, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json') ->withStatus(200) ->withBody($body); } public function isValid(Throwable $throwable): bool { return true; } }