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

api-platform / core / 6067528200

04 Sep 2023 12:12AM UTC coverage: 36.875% (-21.9%) from 58.794%
6067528200

Pull #5791

github

web-flow
Merge 64157e578 into d09cfc9d2
Pull Request #5791: fix: strip down any sql function name

3096 of 3096 new or added lines in 205 files covered. (100.0%)

9926 of 26918 relevant lines covered (36.87%)

6.5 hits per line

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

18.75
/src/ApiResource/Error.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\ApiResource;
15

16
use ApiPlatform\JsonLd\ContextBuilderInterface;
17
use ApiPlatform\Metadata\ApiProperty;
18
use ApiPlatform\Metadata\Error as Operation;
19
use ApiPlatform\Metadata\ErrorResource;
20
use ApiPlatform\Metadata\Exception\HttpExceptionInterface;
21
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
22
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as SymfonyHttpExceptionInterface;
23
use Symfony\Component\Serializer\Annotation\Groups;
24
use Symfony\Component\Serializer\Annotation\Ignore;
25
use Symfony\Component\Serializer\Annotation\SerializedName;
26
use Symfony\Component\WebLink\Link;
27

28
#[ErrorResource(
29
    uriTemplate: '/errors/{status}',
30
    types: ['hydra:Error'],
31
    openapi: false,
32
    operations: [
33
        new Operation(name: '_api_errors_problem', outputFormats: ['json' => ['application/problem+json']], normalizationContext: ['groups' => ['jsonproblem'], 'skip_null_values' => true]),
34
        new Operation(
35
            name: '_api_errors_hydra',
36
            outputFormats: ['jsonld' => ['application/problem+json']],
37
            normalizationContext: [
38
                'groups' => ['jsonld'],
39
                'skip_null_values' => true,
40
            ],
41
            links: [new Link(rel: ContextBuilderInterface::JSONLD_NS.'error', href: 'http://www.w3.org/ns/hydra/error')]
42
        ),
43
        new Operation(name: '_api_errors_jsonapi', outputFormats: ['jsonapi' => ['application/vnd.api+json']], normalizationContext: ['groups' => ['jsonapi'], 'skip_null_values' => true]),
44
    ]
45
)]
46
class Error extends \Exception implements ProblemExceptionInterface, HttpExceptionInterface
47
{
48
    public function __construct(
49
        private readonly string $title,
50
        private readonly string $detail,
51
        #[ApiProperty(identifier: true)] private readonly int $status,
52
        private readonly array $originalTrace,
53
        private ?string $instance = null,
54
        private string $type = 'about:blank',
55
        private array $headers = []
56
    ) {
57
        parent::__construct();
9✔
58
    }
59

60
    #[SerializedName('hydra:title')]
61
    #[Groups(['jsonld', 'legacy_jsonld'])]
62
    public function getHydraTitle(): string
63
    {
64
        return $this->title;
×
65
    }
66

67
    #[SerializedName('trace')]
68
    #[Groups(['trace'])]
69
    public function getOriginalTrace(): array
70
    {
71
        return $this->originalTrace;
×
72
    }
73

74
    #[SerializedName('hydra:description')]
75
    #[Groups(['jsonld', 'legacy_jsonld'])]
76
    public function getHydraDescription(): string
77
    {
78
        return $this->detail;
×
79
    }
80

81
    #[SerializedName('description')]
82
    #[Groups(['jsonapi', 'legacy_jsonapi'])]
83
    public function getDescription(): string
84
    {
85
        return $this->detail;
×
86
    }
87

88
    public static function createFromException(\Exception|\Throwable $exception, int $status): self
89
    {
90
        $headers = ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface) ? $exception->getHeaders() : [];
9✔
91

92
        return new self('An error occurred', $exception->getMessage(), $status, $exception->getTrace(), type: '/errors/'.$status, headers: $headers);
9✔
93
    }
94

95
    #[Ignore]
96
    public function getHeaders(): array
97
    {
98
        return $this->headers;
×
99
    }
100

101
    #[Ignore]
102
    public function getStatusCode(): int
103
    {
104
        return $this->status;
×
105
    }
106

107
    public function setHeaders(array $headers): void
108
    {
109
        $this->headers = $headers;
×
110
    }
111

112
    #[Groups(['jsonld', 'jsonproblem'])]
113
    public function getType(): string
114
    {
115
        return $this->type;
×
116
    }
117

118
    #[Groups(['jsonld', 'legacy_jsonproblem', 'jsonproblem', 'jsonapi', 'legacy_jsonapi'])]
119
    public function getTitle(): ?string
120
    {
121
        return $this->title;
×
122
    }
123

124
    public function setType(string $type): void
125
    {
126
        $this->type = $type;
×
127
    }
128

129
    #[Groups(['jsonld', 'jsonproblem', 'legacy_jsonproblem'])]
130
    public function getStatus(): ?int
131
    {
132
        return $this->status;
×
133
    }
134

135
    #[Groups(['jsonld', 'jsonproblem', 'legacy_jsonproblem'])]
136
    public function getDetail(): ?string
137
    {
138
        return $this->detail;
×
139
    }
140

141
    #[Groups(['jsonld', 'jsonproblem', 'legacy_jsonproblem'])]
142
    public function getInstance(): ?string
143
    {
144
        return $this->instance;
×
145
    }
146
}
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