PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.0
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Hooks / Handlers / ExceptionHandler.php

ExceptionHandler.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.4.0, at app/Hooks/Handlers/ExceptionHandler.php

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Hooks\Handlers;
4
5 class ExceptionHandler
6 {
7 protected $handlers = [
8 'InvalidArgumentException' => 'handleInvalidArgumentException',
9 'FluentSupport\Framework\Foundation\ForbiddenException' => 'handleForbiddenException',
10 'FluentSupport\Framework\Validator\ValidationException' => 'handleValidationException',
11 'FluentSupport\Framework\Foundation\UnAuthorizedException' => 'handleUnAuthorizedException',
12 'FluentSupport\Framework\Database\Orm\ModelNotFoundException' => 'handleModelNotFoundException',
13 ];
14
15 public function handle($e)
16 {
17 foreach ($this->handlers as $key => $value) {
18 if ($e instanceof $key) {
19 return $this->{$value}($e);
20 }
21 }
22 }
23
24 public function handleInvalidArgumentException($e)
25 {
26 wp_send_json_error([
27 'message' => $e->getMessage()
28 ], $e->getCode() ?: 422);
29 }
30
31 public function handleModelNotFoundException($e)
32 {
33 wp_send_json_error([
34 'message' => $e->getMessage()
35 ], $e->getCode() ?: 404);
36 }
37
38 public function handleUnAuthorizedException($e)
39 {
40 wp_send_json_error([
41 'message' => $e->getMessage()
42 ], $e->getCode() ?: 401);
43 }
44
45 public function handleForbiddenException($e)
46 {
47 wp_send_json_error([
48 'message' => $e->getMessage()
49 ], $e->getCode() ?: 403);
50 }
51
52 public function handleValidationException($e)
53 {
54 wp_send_json_error([
55 'message' => $e->getMessage(),
56 'errors' => $e->errors()
57 ], $e->getCode() ?: 422);
58 }
59 }
60