generated from liutk/owl-admin-base
Update
parent
fd5c2c679e
commit
1dcc10d0d3
|
|
@ -41,7 +41,7 @@ abstract class AdminController extends Controller
|
||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
throw $this->prepareException($th);
|
return $this->renderException($th);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->response()->successMessage(__('admin.save').__('admin.successfully'));
|
return $this->response()->successMessage(__('admin.save').__('admin.successfully'));
|
||||||
|
|
@ -70,7 +70,7 @@ abstract class AdminController extends Controller
|
||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
throw $this->prepareException($th);
|
return $this->renderException($th);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->response()->successMessage(__('admin.save').__('admin.successfully'));
|
return $this->response()->successMessage(__('admin.save').__('admin.successfully'));
|
||||||
|
|
@ -89,7 +89,7 @@ abstract class AdminController extends Controller
|
||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
throw $this->prepareException($th);
|
return $this->renderException($th);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->response()->successMessage(__('admin.delete').__('admin.successfully'));
|
return $this->response()->successMessage(__('admin.delete').__('admin.successfully'));
|
||||||
|
|
@ -106,16 +106,23 @@ abstract class AdminController extends Controller
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareException(Throwable $e)
|
protected function renderException(Throwable $e)
|
||||||
{
|
{
|
||||||
|
report($e);
|
||||||
|
|
||||||
|
if ($e instanceof AdminException) {
|
||||||
|
return $e->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = $e->getMessage();
|
||||||
|
|
||||||
if ($e instanceof ValidationException) {
|
if ($e instanceof ValidationException) {
|
||||||
$message = Arr::first($e->errors());
|
$message = Arr::first($e->errors());
|
||||||
if (is_array($message)) {
|
if (is_array($message)) {
|
||||||
$message = Arr::first($message);
|
$message = Arr::first($message) ?: '参数错误';
|
||||||
}
|
}
|
||||||
$e = new AdminException($message ?: '参数错误');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $e;
|
return $this->response()->fail($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Illuminate\Http\{Request};
|
use Illuminate\Http\{Request};
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Slowlyo\OwlAdmin\Exceptions\AdminException;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
|
|
@ -21,6 +22,7 @@ class Handler extends ExceptionHandler
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $dontReport = [
|
protected $dontReport = [
|
||||||
|
AdminException::class,
|
||||||
RuntimeException::class,
|
RuntimeException::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue