PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev2
Elementor Website Builder – more than just a page builder v4.0.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / variables / services / batch-operations / batch-error-formatter.php

batch-error-formatter.php in Elementor Website Builder – more than just a page builder 4.0.0-dev2, at modules/variables/services/batch-operations/batch-error-formatter.php

47 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Variables\Services\Batch_Operations;
4
5 use Exception;
6 use Elementor\Modules\Variables\Storage\Exceptions\DuplicatedLabel;
7 use Elementor\Modules\Variables\Storage\Exceptions\RecordNotFound;
8 use Elementor\Modules\Variables\Storage\Exceptions\VariablesLimitReached;
9
10 class Batch_Error_Formatter {
11
12 private const ERROR_MAP = [
13 RecordNotFound::class => [
14 'code' => 'variable_not_found',
15 'status' => 404,
16 ],
17 DuplicatedLabel::class => [
18 'code' => 'duplicated_label',
19 'status' => 400,
20 ],
21 VariablesLimitReached::class => [
22 'code' => 'invalid_variable_limit_reached',
23 'status' => 400,
24 ],
25 ];
26
27 public function status_for( Exception $e ): int {
28 foreach ( self::ERROR_MAP as $class => $map ) {
29 if ( $e instanceof $class ) {
30 return $map['status'];
31 }
32 }
33
34 return 500;
35 }
36
37 public function error_code_for( Exception $e ): string {
38 foreach ( self::ERROR_MAP as $class => $map ) {
39 if ( $e instanceof $class ) {
40 return $map['code'];
41 }
42 }
43
44 return 'unexpected_server_error';
45 }
46 }
47