Browse Source

修改异常获补货

master
xyiege 1 year ago
parent
commit
2a1d03f8cf
  1. 27
      app/ExceptionHandle.php

27
app/ExceptionHandle.php

@ -34,10 +34,20 @@ class ExceptionHandle extends Handle
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
public function report(Throwable $exception): Response
{
// 使用内置的方式记录异常日志
parent::report($exception);
// 手动触发的异常 BaseException
if ($e instanceof BaseException) {
$this->status = $e->status;
$this->message = $e->message;
$this->data = $e->data;
$extend = property_exists($e, 'extend') ? $e->extend : [];
return $this->output($extend);
}else{
// 使用内置的方式记录异常日志
parent::report($exception);
}
}
/**
@ -55,4 +65,15 @@ class ExceptionHandle extends Handle
// 其他错误交给系统处理
return parent::render($request, $e);
}
/**
* 返回json格式数据
* @param array $extend 扩展的数据
* @return Json
*/
private function output(array $extend = []): Json
{
$jsonData = ['message' => $this->message, 'status' => $this->status, 'data' => $this->data];
return json(array_merge($jsonData, $extend));
}
}

Loading…
Cancel
Save