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

bvlion / AppTanServer / 20205654148

14 Dec 2025 09:04AM UTC coverage: 25.627%. First build
20205654148

push

github

bvlion
format

12 of 49 new or added lines in 18 files covered. (24.49%)

143 of 558 relevant lines covered (25.63%)

0.8 hits per line

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

0.0
/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;
×
28
    $statusCode = 500;
×
29
    $error = new ActionError(
×
30
      ActionError::SERVER_ERROR,
×
31
      'An internal error has occurred while processing your request.'
×
32
    );
×
33

34
    if ($exception instanceof HttpException) {
×
35
      $statusCode = $exception->getCode();
×
36
      $error->setDescription($exception->getMessage());
×
37

38
      if ($exception instanceof HttpNotFoundException) {
×
39
        $error->setType(ActionError::RESOURCE_NOT_FOUND);
×
40
      } elseif ($exception instanceof HttpMethodNotAllowedException) {
×
41
        $error->setType(ActionError::NOT_ALLOWED);
×
42
      } elseif ($exception instanceof HttpUnauthorizedException) {
×
43
        $error->setType(ActionError::UNAUTHENTICATED);
×
44
      } elseif ($exception instanceof HttpForbiddenException) {
×
45
        $error->setType(ActionError::INSUFFICIENT_PRIVILEGES);
×
46
      } elseif ($exception instanceof HttpBadRequestException) {
×
47
        $error->setType(ActionError::BAD_REQUEST);
×
48
      } elseif ($exception instanceof HttpNotImplementedException) {
×
49
        $error->setType(ActionError::NOT_IMPLEMENTED);
×
50
      }
51
    }
52

53
    if (
NEW
54
          !($exception instanceof HttpException)
×
NEW
55
          && $exception instanceof Throwable
×
NEW
56
          && $this->displayErrorDetails
×
57
    ) {
58
      $error->setDescription($exception->getMessage());
×
59
    }
60

61
    $payload = new ActionPayload($statusCode, null, $error);
×
62
    $encodedPayload = json_encode($payload, JSON_PRETTY_PRINT);
×
63

64
    $response = $this->responseFactory->createResponse($statusCode);
×
65
    $response->getBody()->write($encodedPayload);
×
66

67
    return $response->withHeader('Content-Type', 'application/json');
×
68
  }
69
}
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