Files
piratepoet/mailpoet/lib/API/JSON/ErrorHandler.php
David Remer b05e6d414c Remove WP\Functions::__ and other translate functions
Under the new sniffer rules, those functions produce errors and, when those methods
are used, the sniffer can not properly be applied.

[MAILPOET-4524]
2022-08-09 13:23:16 +02:00

27 lines
757 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 __construct() {
$this->defaultErrors = [
Error::UNKNOWN => __('An unknown error occurred.', 'mailpoet'),
];
}
public function convertToResponse(\Throwable $e): ErrorResponse {
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);
}
}