PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.59.2
MailPoet – Newsletters, Email Marketing, and Automation v3.59.2
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 / ErrorResponse.php

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

35 lines 874 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailPoet\API\JSON;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\WP\Functions as WPFunctions;
9
10 class ErrorResponse extends Response {
11 public $errors;
12
13 public function __construct($errors = [], $meta = [], $status = self::STATUS_NOT_FOUND) {
14 parent::__construct($status, $meta);
15 $this->errors = $this->formatErrors($errors);
16 }
17
18 public function getData() {
19 return (empty($this->errors)) ? null : ['errors' => $this->errors];
20 }
21
22 public function formatErrors($errors = []) {
23 return array_map(function($error, $message) {
24 // sanitize SQL error
25 if (preg_match('/^SQLSTATE/i', $message)) {
26 $message = WPFunctions::get()->__('An unknown error occurred.', 'mailpoet');
27 }
28 return [
29 'error' => $error,
30 'message' => $message,
31 ];
32 }, array_keys($errors), array_values($errors));
33 }
34 }
35