Files
piratepoet/mailpoet/lib/API/JSON/ErrorHandler.php
Oluwaseun Olorunsola 6ea5074649 Move WP translation function from __construct
According to this post https://make.wordpress.org/core/2024/10/21/i18n-improvements-6-7/, we are currently doing_it_wrong

MAILPOET-6298
2024-10-31 15:54:28 +02:00

23 lines
707 B
PHP

<?php declare(strict_types = 1);
namespace MailPoet\API\JSON;
use MailPoet\Exception;
use MailPoet\HttpAwareException;
class ErrorHandler {
/** @var string[] */
private $defaultErrors = [];
public function convertToResponse(\Throwable $e): ErrorResponse {
$this->defaultErrors[Error::UNKNOWN] = __('An unknown error occurred.', 'mailpoet');
if ($e instanceof Exception) {
$errors = $e->getErrors() ?: $this->defaultErrors;
$statusCode = $e instanceof HttpAwareException ? $e->getHttpStatusCode() : Response::STATUS_UNKNOWN;
return new ErrorResponse($errors, [], $statusCode);
}
return new ErrorResponse($this->defaultErrors, [], Response::STATUS_UNKNOWN);
}
}