forked from woohoolabs/yin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaTypeUnacceptable.php
39 lines (32 loc) · 1023 Bytes
/
MediaTypeUnacceptable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace WoohooLabs\Yin\JsonApi\Exception;
use WoohooLabs\Yin\JsonApi\Schema\Error\Error;
use WoohooLabs\Yin\JsonApi\Schema\Error\ErrorSource;
class MediaTypeUnacceptable extends AbstractJsonApiException
{
/**
* @var string
*/
protected $mediaTypeName;
public function __construct(string $mediaTypeName)
{
parent::__construct("The media type '" . $mediaTypeName . "' is unacceptable in the 'Accept' header!", 406);
$this->mediaTypeName = $mediaTypeName;
}
protected function getErrors(): array
{
return [
Error::create()
->setStatus("406")
->setCode("MEDIA_TYPE_UNACCEPTABLE")
->setTitle("The provided media type is unacceptable")
->setDetail($this->getMessage())
->setSource(ErrorSource::fromParameter("accept")),
];
}
public function getMediaTypeName(): string
{
return $this->mediaTypeName;
}
}