logger->error('mini_api.error', [ 'request_id' => ApiResponse::requestId($request), 'exception_type' => get_class($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => array_map(static fn ($frame) => array_intersect_key($frame, array_flip([ 'file', 'line', 'class', 'function', ])), array_slice($exception->getTrace(), 0, 15)), ]); } } public function render(Request $request, \Throwable $exception): Response { if (!ApiResponse::owns($request)) { return parent::render($request, $exception); } $error = $exception instanceof ApiException ? $exception : ($exception instanceof \plugin\saiadmin\exception\ApiException ? new ApiException(40902, $exception->getMessage(), 409) : new ApiException(50001, '服务暂时不可用', 500)); return ApiResponse::error($request, $error); } }