mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Rest\Exception;
|
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
|
use Zend\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
|
use Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
|
|
|
use function implode;
|
|
use function sprintf;
|
|
|
|
class MissingAuthenticationException extends RuntimeException implements ProblemDetailsExceptionInterface
|
|
{
|
|
use CommonProblemDetailsExceptionTrait;
|
|
|
|
private const TITLE = 'Invalid authorization';
|
|
private const TYPE = 'INVALID_AUTHORIZATION';
|
|
|
|
public static function fromExpectedTypes(array $expectedTypes): self
|
|
{
|
|
$e = new self(sprintf(
|
|
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
|
implode('", "', $expectedTypes),
|
|
));
|
|
|
|
$e->detail = $e->getMessage();
|
|
$e->title = self::TITLE;
|
|
$e->type = self::TYPE;
|
|
$e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
|
|
$e->additional = ['expectedTypes' => $expectedTypes];
|
|
|
|
return $e;
|
|
}
|
|
}
|