Skip to content

Commit 928dfa4

Browse files
authored
Merge pull request #22 from brainstudnl/feature/map-default-symfony-405
Map symfony 405 exception to ApiException
2 parents f7e1450 + c688076 commit 928dfa4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Handlers/JsonApiExceptionHandler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Brainstud\JsonApi\Exceptions\BadRequestJsonApiException;
66
use Brainstud\JsonApi\Exceptions\JsonApiExceptionInterface;
7+
use Brainstud\JsonApi\Exceptions\MethodNotAllowedJsonApiException;
78
use Brainstud\JsonApi\Exceptions\NotFoundJsonApiException;
89
use Brainstud\JsonApi\Responses\ErrorResponse;
910
use Brainstud\JsonApi\Responses\Errors\DefaultError;
@@ -14,6 +15,8 @@
1415
use Illuminate\Validation\ValidationException;
1516
use RuntimeException;
1617
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
18+
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
19+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1720
use Throwable;
1821

1922
/**
@@ -48,6 +51,14 @@ public function register(): void
4851
))->withErrorName('LAZY_LOADING_VIOLATION');
4952
});
5053

54+
$this->map(function (MethodNotAllowedHttpException|MethodNotAllowedException $exception) {
55+
return (new MethodNotAllowedJsonApiException(
56+
message: $exception->getMessage(),
57+
previous: $exception->getPrevious(),
58+
code: $exception->getCode(),
59+
))->withErrorName('METHOD_NOT_ALLOWED');
60+
});
61+
5162
$this->renderable(function (JsonApiExceptionInterface $exception) {
5263
return ErrorResponse::make([new DefaultError(
5364
(isset($exception->errorName) ? $exception->errorName : ''),

0 commit comments

Comments
 (0)