Skip to content

Commit

Permalink
fix: corrige erreurs remontées par phpmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Nov 23, 2023
1 parent cf9654d commit cf984cd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<exclude name="ElseExpression" />
<exclude name="StaticAccess" />
<exclude name="MissingImport" />
<exclude name="BooleanArgumentFlag" />
</rule>
<!--
<rule ref="rulesets/codesize.xml" />
Expand Down
5 changes: 3 additions & 2 deletions src/Listener/CartesApiExceptionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ public function onCartesApiException(ExceptionEvent $event): void

private function getErrorResponse(CartesApiException $throwable): JsonResponse
{
$statusText = 'Internal Server Error';
$responseData = [
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
'status' => Response::$statusTexts[Response::HTTP_INTERNAL_SERVER_ERROR],
'status' => $statusText,
'message' => 'An internal error has occurred',
'details' => [],
];

if ($throwable instanceof CartesApiException) {
$code = $throwable->getCode();
$responseData['code'] = $code;
$responseData['status'] = Response::$statusTexts[$code];
$responseData['status'] = $statusText;
$responseData['message'] = $throwable->getMessage();
$responseData['details'] = $throwable->getDetails();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/InternalApiSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function onKernelController(ControllerEvent $event): void
// TODO préciser que c'est l'API interne
if (null == $accessToken
|| (null != $accessToken && $accessToken->hasExpired())) {
throw new CartesApiException(Response::$statusTexts[Response::HTTP_UNAUTHORIZED], Response::HTTP_UNAUTHORIZED, ['controller' => ApiControllerInterface::class]);
throw new CartesApiException('Unauthorized', Response::HTTP_UNAUTHORIZED, ['controller' => ApiControllerInterface::class]);
}
}
}
Expand Down

0 comments on commit cf984cd

Please sign in to comment.