PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 5.38.0
MailPoet – Newsletters, Email Marketing, and Automation v5.38.0
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / API / JSON / ErrorHandler.php

ErrorHandler.php in MailPoet – Newsletters, Email Marketing, and Automation 5.38.0, at lib/API/JSON/ErrorHandler.php

26 lines 740 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types = 1);
2
3 namespace MailPoet\API\JSON;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Exception;
9 use MailPoet\HttpAwareException;
10
11 class ErrorHandler {
12 /** @var string[] */
13 private $defaultErrors = [];
14
15 public function convertToResponse(\Throwable $e): ErrorResponse {
16 $this->defaultErrors[Error::UNKNOWN] = __('An unknown error occurred.', 'mailpoet');
17
18 if ($e instanceof Exception) {
19 $errors = $e->getErrors() ?: $this->defaultErrors;
20 $statusCode = $e instanceof HttpAwareException ? $e->getHttpStatusCode() : Response::STATUS_UNKNOWN;
21 return new ErrorResponse($errors, [], $statusCode);
22 }
23 return new ErrorResponse($this->defaultErrors, [], Response::STATUS_UNKNOWN);
24 }
25 }
26