aboutsummaryrefslogtreecommitdiff
path: root/middlewares/ExceptionMiddleware.php
blob: 8bb7471365a0b856069a40015beb06c8df235a17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

declare(strict_types=1);

class ExceptionMiddleware implements Middleware
{
    private Logger $logger;

    public function __construct(Logger $logger)
    {
        $this->logger = $logger;
    }

    public function __invoke(Request $request, $next): Response
    {
        try {
            return $next($request);
        } catch (\Throwable $e) {
            $this->logger->error('Exception in ExceptionMiddleware', ['e' => $e]);

            return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 500);
        }
    }
}