Skip to content

Commit

Permalink
Improve error messaging in auth exceptions
Browse files Browse the repository at this point in the history
Enhanced the error messaging for Auth exceptions with more descriptive information. Now, when an Unauthorized Access exception occurs, it will return the HTTP status code's official reason phrase, rather than just the code, to provide more context to the client. This change is in the Authentication middleware and
  • Loading branch information
AuroraYolo committed Aug 30, 2023
1 parent 712badd commit 89d6915
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Exception/AuthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class AuthException extends HttpException
{
public function __construct(int $code = Status::UNAUTHORIZED, string $message = null, ?Throwable $previous = null)
{
parent::__construct($code, $message, $previous);
parent::__construct(statusCode: $code, message: $message);
}
}
2 changes: 1 addition & 1 deletion app/Middleware/Auth/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$token = $request->getHeaderLine('Authorization') ?? '';

if ($token === '') {
return $this->response->handleException(new AuthException(Status::BAD_REQUEST));
return $this->response->handleException(new AuthException(Status::BAD_REQUEST, \Hyperf\HttpMessage\Base\Response::getReasonPhraseByCode(Status::BAD_REQUEST)));
}

$token = JWTUtil::handleToken($token);
Expand Down

0 comments on commit 89d6915

Please sign in to comment.