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

slimphp / Slim-Skeleton / 12974041205

26 Jan 2025 11:05AM UTC coverage: 59.42% (-0.07%) from 59.494%
12974041205

Pull #345

github

web-flow
Merge 7f32837f9 into 0ef015498
Pull Request #345: Upgrading Skeleton to PHP 8.4

7 of 22 new or added lines in 4 files covered. (31.82%)

82 of 138 relevant lines covered (59.42%)

2.06 hits per line

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

60.71
/src/Application/Handlers/HttpErrorHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Application\Handlers;
6

7
use App\Application\Actions\ActionError;
8
use App\Application\Actions\ActionPayload;
9
use Psr\Http\Message\ResponseInterface as Response;
10
use Slim\Exception\HttpBadRequestException;
11
use Slim\Exception\HttpException;
12
use Slim\Exception\HttpForbiddenException;
13
use Slim\Exception\HttpMethodNotAllowedException;
14
use Slim\Exception\HttpNotFoundException;
15
use Slim\Exception\HttpNotImplementedException;
16
use Slim\Exception\HttpUnauthorizedException;
17
use Slim\Handlers\ErrorHandler as SlimErrorHandler;
18
use Throwable;
19

20
class HttpErrorHandler extends SlimErrorHandler
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    protected function respond(): Response
26
    {
27
        $exception = $this->exception;
1✔
28
        $statusCode = 500;
1✔
29
        $errorType = ActionError::SERVER_ERROR;
1✔
30
        $description = 'An internal error has occurred while processing your request.';
1✔
31

32
        if ($exception instanceof HttpException) {
1✔
33
            $statusCode = $exception->getCode();
1✔
34
            $description = $exception->getMessage();
1✔
35

36
            if ($exception instanceof HttpNotFoundException) {
1✔
37
                $errorType = ActionError::RESOURCE_NOT_FOUND;
1✔
38
            } elseif ($exception instanceof HttpMethodNotAllowedException) {
×
NEW
39
                $errorType = ActionError::NOT_ALLOWED;
×
40
            } elseif ($exception instanceof HttpUnauthorizedException) {
×
NEW
41
                $errorType = ActionError::UNAUTHENTICATED;
×
42
            } elseif ($exception instanceof HttpForbiddenException) {
×
NEW
43
                $errorType = ActionError::INSUFFICIENT_PRIVILEGES;
×
44
            } elseif ($exception instanceof HttpBadRequestException) {
×
NEW
45
                $errorType = ActionError::BAD_REQUEST;
×
46
            } elseif ($exception instanceof HttpNotImplementedException) {
×
NEW
47
                $errorType = ActionError::NOT_IMPLEMENTED;
×
48
            }
49
        }
50

51
        if (
52
            !($exception instanceof HttpException)
1✔
53
            && $this->displayErrorDetails
1✔
54
        ) {
NEW
55
            $description = $exception->getMessage();
×
56
        }
57

58
        $error = new ActionError($errorType, $description);
1✔
59
        $payload = new ActionPayload($statusCode, null, $error);
1✔
60
        $encodedPayload = json_encode($payload, JSON_PRETTY_PRINT);
1✔
61

62
        $response = $this->responseFactory->createResponse($statusCode);
1✔
63
        $response->getBody()->write($encodedPayload);
1✔
64

65
        return $response->withHeader('Content-Type', 'application/json');
1✔
66
    }
67
}
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