};
if (!$isSupportedVerb) {
- return $this->toErrorResponse(RequestFailure::METHOD_NOT_ALLOWED, 'unacceptable_method');
+ return $this->toErrorResponse(RequestFailure::MethodNotAllowed, 'unacceptable_method');
}
$endpoint = $this->getEndpointFromPathInfo(RouteHandler::getPathInfo());
if ($endpoint === null) {
- return $this->toErrorResponse(RequestFailure::UNKNOWN_ENDPOINT, 'missing_endpoint');
+ return $this->toErrorResponse(RequestFailure::UnknownEndpoint, 'missing_endpoint');
}
// TODO: This is currently very inefficient and should be cached in some
$result = $dispatcher->dispatch($request->getMethod(), $endpoint);
if ($result instanceof NotMatched) {
- return $this->toErrorResponse(RequestFailure::UNKNOWN_ENDPOINT, 'unknown_endpoint');
+ return $this->toErrorResponse(RequestFailure::UnknownEndpoint, 'unknown_endpoint');
}
if ($result instanceof MethodNotAllowed) {
- return $this->toErrorResponse(RequestFailure::METHOD_NOT_ALLOWED, 'endpoint_does_not_allow_method');
+ return $this->toErrorResponse(RequestFailure::MethodNotAllowed, 'endpoint_does_not_allow_method');
}
/** @var IController */
try {
return $controller($request, $result->variables);
} catch (MappingError $e) {
- return $this->toErrorResponse(RequestFailure::VALIDATION_FAILED, 'mapping_error', $e->getMessage());
+ return $this->toErrorResponse(RequestFailure::ValidationFailed, 'mapping_error', $e->getMessage());
} catch (PermissionDeniedException) {
- return $this->toErrorResponse(RequestFailure::PERMISSION_DENIED, 'permission_denied');
+ return $this->toErrorResponse(RequestFailure::PermissionDenied, 'permission_denied');
} catch (UserInputException $e) {
- return $this->toErrorResponse(RequestFailure::VALIDATION_FAILED, $e->getType(), $e->getMessage(), $e->getField());
+ return $this->toErrorResponse(RequestFailure::ValidationFailed, $e->getType(), $e->getMessage(), $e->getField());
} catch (\Throwable $e) {
- return $this->toErrorResponse(RequestFailure::INTERNAL_ERROR, 'unknown_exception', $e->getMessage());
+ return $this->toErrorResponse(RequestFailure::InternalError, 'unknown_exception', $e->getMessage());
}
}
enum RequestFailure
{
- case INTERNAL_ERROR;
- case METHOD_NOT_ALLOWED;
- case PERMISSION_DENIED;
- case VALIDATION_FAILED;
- case UNKNOWN_ENDPOINT;
+ case InternalError;
+ case MethodNotAllowed;
+ case PermissionDenied;
+ case ValidationFailed;
+ case UnknownEndpoint;
public function toString(): string
{
return match ($this) {
- self::INTERNAL_ERROR => 'api_error',
- self::METHOD_NOT_ALLOWED => 'invalid_request_error',
- self::PERMISSION_DENIED => 'invalid_request_error',
- self::VALIDATION_FAILED => 'invalid_request_error',
- self::UNKNOWN_ENDPOINT => 'invalid_request_error',
+ self::InternalError => 'api_error',
+ self::MethodNotAllowed => 'invalid_request_error',
+ self::PermissionDenied => 'invalid_request_error',
+ self::ValidationFailed => 'invalid_request_error',
+ self::UnknownEndpoint => 'invalid_request_error',
};
}
public function toStatusCode(): int
{
return match ($this) {
- self::INTERNAL_ERROR => 503,
- self::METHOD_NOT_ALLOWED => 405,
- self::PERMISSION_DENIED => 403,
- self::VALIDATION_FAILED => 400,
- self::UNKNOWN_ENDPOINT => 404,
+ self::InternalError => 503,
+ self::MethodNotAllowed => 405,
+ self::PermissionDenied => 403,
+ self::ValidationFailed => 400,
+ self::UnknownEndpoint => 404,
};
}
}