PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Controllers/Controller.php +27 -9 0.4 → 1.5.1 View file →
@@ -1,21 +1,18 @@
1 1 <?php
2 2
3 3 /**
4 - * @copyright © TMS-Plugins. All rights reserved.
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 5 * @licence See COPYING.md for license details.
6 6 */
7 7
8 8 namespace IvyForms\Controllers;
9 9
10 -// phpcs:disable PSR1.Files.SideEffects
11 -if (!defined('ABSPATH')) {
12 - exit; // Exit if accessed directly
13 -}
14 -
15 10 use IvyForms\Common\Exceptions\InvalidArgumentException;
16 11 use IvyForms\Common\Exceptions\NotFoundException;
17 12 use IvyForms\Common\Exceptions\QueryExecutionException;
13 +use IvyForms\Common\Exceptions\ServiceUnavailableException;
14 +use IvyForms\Common\Exceptions\FieldValidationException;
18 15 use IvyForms\Common\Exceptions\ValidationException;
19 16 use IvyForms\Common\Exceptions\ForbiddenException;
20 17 use IvyForms\Services\Translations\BackendStrings;
21 18 use RuntimeException;
@@ -41,9 +38,11 @@
41 38 try {
42 39 $response = $this->handle($data);
43 40
44 41 if ($response->get_status() !== 200) {
45 - throw new RuntimeException("Unexpected HTTP status code: {$response->get_status()}");
42 + throw new RuntimeException(
43 + BackendStrings::getExceptionStrings()['unexpected_http_status'] . ": {$response->get_status()}"
44 + );
46 45 }
47 46
48 47 return new WP_REST_Response([
49 48 'message' => BackendStrings::getCommonStrings()['ok'],
@@ -70,8 +69,17 @@
70 69 return new WP_REST_Response([
71 70 'message' => $e->getMessage(),
72 71 'data' => []
73 72 ], 404);
73 + } catch (ServiceUnavailableException $e) {
74 + if (defined('WP_DEBUG') && WP_DEBUG) {
75 + error_log('Error 503: ' . $e->getMessage());
76 + }
77 +
78 + return new WP_REST_Response([
79 + 'message' => $e->getMessage(),
80 + 'data' => []
81 + ], 503);
74 82 } catch (InvalidArgumentException $e) {
75 83 // Log errors
76 84 if (defined('WP_DEBUG') && WP_DEBUG) {
77 85 error_log('Error: ' . $e->getMessage());
@@ -88,11 +96,21 @@
88 96 error_log('Validation error: ' . $e->getMessage());
89 97 }
90 98 // Handle validation for data
91 99 // HTTP 422 Unprocessable Content
100 + $data = [];
101 + $fieldErrors = $e->getFieldErrors();
102 + if ($fieldErrors !== []) {
103 + if ($e instanceof FieldValidationException) {
104 + $data['field_errors'] = $fieldErrors;
105 + } else {
106 + $data['fieldErrors'] = $fieldErrors;
107 + }
108 + }
109 +
92 110 return new WP_REST_Response([
93 - 'message' => 'Validation error: ' . $e->getMessage(),
94 - 'data' => []
111 + 'message' => $e->getMessage(),
112 + 'data' => $data,
95 113 ], 422);
96 114 } catch (QueryExecutionException $e) {
97 115 // Log errors
98 116 if (defined('WP_DEBUG') && WP_DEBUG) {