mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
[exam] finish assign and remove
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\UnauthorizedException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
@@ -47,6 +49,10 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(fail($e->getMessage(), $e->guards()), 401);
|
||||
});
|
||||
|
||||
$this->renderable(function (UnauthorizedException $e) {
|
||||
return response()->json(fail($e->getMessage(), request()->all()), 403);
|
||||
});
|
||||
|
||||
$this->renderable(function (ValidationException $exception) {
|
||||
$errors = $exception->errors();
|
||||
$msg = Arr::first(Arr::first($errors));
|
||||
@@ -54,7 +60,9 @@ class Handler extends ExceptionHandler
|
||||
});
|
||||
|
||||
$this->renderable(function (NotFoundHttpException $e) {
|
||||
return response()->json(fail('No query result.', request()->all()), 404);
|
||||
if ($e->getPrevious() && $e->getPrevious() instanceof ModelNotFoundException) {
|
||||
return response()->json(fail('No query result.', request()->all()), 404);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,11 +84,23 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
return new JsonResponse(
|
||||
fail($msg, $data),
|
||||
$this->isHttpException($e) ? $e->getStatusCode() : 500,
|
||||
$this->getHttpStatusCode($e),
|
||||
$this->isHttpException($e) ? $e->getHeaders() : [],
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
|
||||
);
|
||||
}
|
||||
|
||||
protected function getHttpStatusCode(Throwable $e)
|
||||
{
|
||||
if ($e instanceof \InvalidArgumentException || $e instanceof NexusException) {
|
||||
return 200;
|
||||
}
|
||||
if ($this->isHttpException($e)) {
|
||||
return $e->getStatusCode();
|
||||
}
|
||||
return 500;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
8
app/Exceptions/NexusException.php
Normal file
8
app/Exceptions/NexusException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class NexusException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user