HEX
Server: LiteSpeed
System: Linux w5304130.sdnsbox.com 4.18.0-425.3.1.lve.el8.x86_64 #1 SMP Tue Nov 22 22:59:23 EST 2022 x86_64
User: makefitmeserver (1001)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/makefitmeserver/public_html/demo/wp-content/plugins/mailpoet/lib/API/JSON/ErrorHandler.php
<?php declare(strict_types = 1);

namespace MailPoet\API\JSON;

if (!defined('ABSPATH')) exit;


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);
  }
}