Skip to content

Commit

Permalink
Don't log 401 as errors
Browse files Browse the repository at this point in the history
Because there is not much we can do about it, so let's not pollute
our alerts channel with this. Logging a warning is enough.
(we also set a response to avoid an uncaught exception being
 thrown afterwards, as this would result in another error being
 logged)
  • Loading branch information
gturri authored Feb 3, 2025
1 parent e4bf347 commit f2253b1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions symfony-server/src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ public function __invoke(Exceptionevent $event): void {
$response = new Response();
$response->setStatusCode(Response::HTTP_NOT_FOUND);
$response->setContent("Not found");
$event->setResponse($response);
} else if ($exception->getStatusCode() === Response::HTTP_UNAUTHORIZED) {
$this->logger->warning("Caught unauthorized access");
$response = new Response();
$response->setStatusCode(Response::HTTP_UNAUTHORIZED);
$response->setContent("Unauthorized");
$event->setResponse($response);
// TODO 1: according to this, perhaps this code could be replaced by some conf on this firewall:
// > No Authentication entry point configured, returning a 401 HTTP response. Configure "entry_point" on the firewall "main" if you want to modify the response.

// TODO 2: Perhaps we should instead redirect to the login page?
} else {
$this->logger->error("Caught exception: " . $exception->getMessage() . "(code: " . $exception->getCode() . "). Stack trace: " . $exception->getTraceAsString());
}
Expand Down

0 comments on commit f2253b1

Please sign in to comment.