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
This commit is contained in:
Oluwaseun Olorunsola
2024-10-28 17:19:34 +01:00
committed by Oluwaseun Olorunsola
parent 1f21add146
commit 6ea5074649
3 changed files with 17 additions and 7 deletions

View File

@ -7,15 +7,11 @@ use MailPoet\HttpAwareException;
class ErrorHandler {
/** @var string[] */
private $defaultErrors;
public function __construct() {
$this->defaultErrors = [
Error::UNKNOWN => __('An unknown error occurred.', 'mailpoet'),
];
}
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;