generated from liutk/owl-admin-base
Compare commits
3 Commits
776842c376
...
7c755b9072
| Author | SHA1 | Date |
|---|---|---|
|
|
7c755b9072 | |
|
|
f35a0e0e6d | |
|
|
7abf180f3b |
|
|
@ -4,9 +4,11 @@ namespace App\Exceptions;
|
||||||
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Illuminate\Http\{Request};
|
use Illuminate\Http\{Request, Response};
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Slowlyo\OwlAdmin\Exceptions\AdminException;
|
use Slowlyo\OwlAdmin\Exceptions\AdminException;
|
||||||
|
use Illuminate\Auth\AuthenticationException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
|
|
@ -34,6 +36,10 @@ class Handler extends ExceptionHandler
|
||||||
$this->renderable(function (RuntimeException $e, Request $request) {
|
$this->renderable(function (RuntimeException $e, Request $request) {
|
||||||
return response(['code' => $e->getCode(), 'message' => $e->getMessage()], $e->getHttpStatusCode());
|
return response(['code' => $e->getCode(), 'message' => $e->getMessage()], $e->getHttpStatusCode());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->renderable(function (NotFoundHttpException $e, Request $request) {
|
||||||
|
return response(['code' => Response::HTTP_NOT_FOUND, 'message' => $e->getMessage()], Response::HTTP_NOT_FOUND);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function invalidJson($request, ValidationException $exception)
|
protected function invalidJson($request, ValidationException $exception)
|
||||||
|
|
@ -44,4 +50,11 @@ class Handler extends ExceptionHandler
|
||||||
'errors' => $exception->errors(),
|
'errors' => $exception->errors(),
|
||||||
], $exception->status);
|
], $exception->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function unauthenticated($request, AuthenticationException $exception)
|
||||||
|
{
|
||||||
|
return $this->shouldReturnJson($request, $exception)
|
||||||
|
? response()->json(['code' => Response::HTTP_UNAUTHORIZED, 'message' => $exception->getMessage()], 401)
|
||||||
|
: redirect()->guest($exception->redirectTo() ?? route('login'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue