Skip to content

Commit

Permalink
Add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Dec 3, 2023
1 parent ae3209e commit f101e1c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Middleware/ExceptionMiddleware.php
Expand Up @@ -50,6 +50,20 @@ private function render(
$httpStatusCode = $this->getHttpStatusCode($exception);
$response = $this->responseFactory->createResponse($httpStatusCode);

// Log error
if (isset($this->logger)) {
$this->logger->error(
sprintf(
'%s;Code %s;File: %s;Line: %s',
$exception->getMessage(),
$exception->getCode(),
$exception->getFile(),
$exception->getLine()
),
$exception->getTrace()
);
}

// Content negotiation
if (str_contains($request->getHeaderLine('Accept'), 'application/json')) {
$response = $response->withAddedHeader('Content-Type', 'application/json');
Expand Down

0 comments on commit f101e1c

Please sign in to comment.