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

AJenbo / agcms / 21419177689

28 Jan 2026 12:03AM UTC coverage: 52.306% (-1.4%) from 53.72%
21419177689

Pull #77

github

web-flow
Merge 25510f18e into 655757ab5
Pull Request #77: Bump phpunit/phpunit from 9.6.11 to 9.6.33 in /application

3039 of 5810 relevant lines covered (52.31%)

12.21 hits per line

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

62.5
/application/inc/Exceptions/Handler.php
1
<?php
2

3
namespace App\Exceptions;
4

5
use App\Http\Request;
6
use App\Services\ConfigService;
7
use Sentry\EventId;
8
use Sentry\State\Scope;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\HttpFoundation\Response;
11
use Throwable;
12

13
class Handler
14
{
15
    private ?EventId $lastLogId;
16

17
    /** @var array<int, string> */
18
    private array $dontReport = [
19
        InvalidInput::class,
20
    ];
21

22
    /**
23
     * Set error loggin.
24
     */
25
    public function __construct()
26
    {
27
        if (app()->environment('production')) {
27✔
28
            \Sentry\init(['dsn' => ConfigService::getString('sentry')]);
×
29
        }
30
    }
31

32
    /**
33
     * Repport the exception.
34
     */
35
    public function report(Throwable $exception): void
36
    {
37
        $this->lastLogId = null;
27✔
38
        if (!$this->shouldLog($exception)) {
27✔
39
            return;
21✔
40
        }
41

42
        if (app()->environment('develop')) {
6✔
43
            http_response_code(Response::HTTP_INTERNAL_SERVER_ERROR);
×
44

45
            throw $exception;
×
46
        }
47

48
        if (app()->environment('productino')) {
6✔
49
            $request = app(Request::class);
×
50
            if ($request->hasSession()) {
×
51
                $user = $request->user();
×
52
                if ($user) {
×
53
                    \Sentry\configureScope(function (Scope $scope) use ($user): void {
×
54
                        $scope->setUser(['id' => $user->getId(), 'name' => $user->getFullName()]);
×
55
                    });
×
56
                }
57
            }
58

59
            $this->lastLogId = \Sentry\captureException($exception);
×
60
        }
61
    }
62

63
    /**
64
     * Generate an error response.
65
     */
66
    public function render(Request $request, Throwable $exception): Response
67
    {
68
        if (app()->environment('test') && $this->shouldLog($exception)) {
21✔
69
            throw $exception;
×
70
        }
71

72
        $status = Response::HTTP_INTERNAL_SERVER_ERROR;
21✔
73
        if ($exception->getCode() >= 400 && $exception->getCode() <= 599) {
21✔
74
            $status = (int)$exception->getCode();
21✔
75
        }
76

77
        if ($request->isXmlHttpRequest()) {
21✔
78
            return new JsonResponse(
1✔
79
                ['error' => ['message' => $exception->getMessage(), 'sentry_id' => $this->lastLogId]],
1✔
80
                $status
1✔
81
            );
1✔
82
        }
83

84
        return new Response($exception->getMessage(), $status);
20✔
85
    }
86

87
    /**
88
     * Determin if the exception should be logged.
89
     */
90
    private function shouldLog(Throwable $exception): bool
91
    {
92
        foreach ($this->dontReport as $className) {
27✔
93
            if ($exception instanceof $className) {
27✔
94
                return false;
21✔
95
            }
96
        }
97

98
        return true;
6✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc