success($callback()); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '数据不存在'); } catch (\InvalidArgumentException | \RuntimeException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } catch (\Throwable $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '系统处理失败,请稍后重试'); } } protected function currentAgent(): Agent { $agent = request()->attributes->get('agent'); if (!$agent instanceof Agent) { throw new \RuntimeException('请先登录'); } return $agent; } }