- Added rate limiting for web and API requests. - Introduced custom error handling for "Too Many Requests" response. - Created view for "Too Many Requests" error documentation.
30 lines
791 B
PHP
30 lines
791 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Presentation\Api\V1\Exceptions;
|
|
|
|
use Shared\Enums\BaseEnum;
|
|
|
|
enum ApiErrorCode: string
|
|
{
|
|
/** @use BaseEnum<string> */
|
|
use BaseEnum;
|
|
|
|
case NotFound = 'not-found';
|
|
case ValidationError = 'validation-error';
|
|
case BadRequest = 'bad-request';
|
|
case TooManyRequests = 'too-many-requests';
|
|
case InternalError = 'internal-error';
|
|
|
|
public function title(): string
|
|
{
|
|
return match ($this) {
|
|
self::NotFound => 'Resource Not Found',
|
|
self::ValidationError => 'Unprocessable Entity',
|
|
self::BadRequest => 'Bad Request',
|
|
self::TooManyRequests => 'Too Many Requests',
|
|
self::InternalError => 'Internal Server Error',
|
|
};
|
|
}
|
|
}
|