• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IGNF / validator-api / 37029673965

02 Oct 2026 03:49PM UTC coverage: 89.794% (+38.5%) from 51.256%
37029673965

push

github

floriancerizay
fix(tests): Fix validation database support for PostgreSQL

871 of 970 relevant lines covered (89.79%)

9.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/EventListener/ExceptionListener.php
1
<?php
2

3
namespace App\EventListener;
4

5
use App\Exception\ApiException;
6
use Psr\Log\LoggerInterface;
7
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
11
use Symfony\Component\HttpKernel\Exception\HttpException;
12
use Symfony\Component\HttpKernel\KernelEvents;
13

14
/**
15
 * Class for custom exception handling.
16
 */
17
#[AsEventListener(event: KernelEvents::EXCEPTION, method: 'onKernelException')]
18
class ExceptionListener
19
{
20
    private $logger;
21

22
    public function __construct(LoggerInterface $logger)
23
    {
24
        $this->logger = $logger;
45 ✔
25
    }
26

27
    /**
28
     * Handles the exception caught by the listener.
29
     */
30
    public function onKernelException(ExceptionEvent $event)
31
    {
32
        $throwable = $event->getThrowable();
45 ✔
33
        $event->setResponse($this->getErrorResponse($throwable));
45 ✔
34
    }
35

36
    /**
37
     * Returns the error response data corresponding to the exception caught by the listener.
38
     *
39
     * @return JsonResponse
40
     */
41
    private function getErrorResponse(\Throwable $throwable)
42
    {
43
        $responseData = [
45 ✔
44
            'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
45 ✔
45
            'status' => Response::$statusTexts[Response::HTTP_INTERNAL_SERVER_ERROR],
45 ✔
46
            'message' => 'An internal error has occurred',
45 ✔
47
            'details' => [],
45 ✔
48
        ];
45 ✔
49

50
        if ($throwable instanceof HttpException) {
45 ✔
51
            $code = $throwable->getStatusCode();
×
52
            $responseData['code'] = $code;
×
53
            $responseData['status'] = Response::$statusTexts[$code];
×
54
            $responseData['message'] = $throwable->getMessage();
×
55
        } elseif ($throwable instanceof ApiException) {
45 ✔
56
            $code = $throwable->getCode();
45 ✔
57
            $responseData['code'] = $code;
45 ✔
58
            $responseData['status'] = Response::$statusTexts[$code];
45 ✔
59
            $responseData['message'] = $throwable->getMessage();
45 ✔
60
            $responseData['details'] = $throwable->getDetails();
45 ✔
61
        }
62

63
        $this->logger->error('Exception[{exception}]: {message}', ['exception' => get_class($throwable), 'message' => $throwable->getMessage()]);
45 ✔
64

65
        return new JsonResponse($responseData, $responseData['code']);
45 ✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc