/var/www/html_nl/wp-content/plugins/fluent-smtp/app/Hooks/Handlers/ExceptionHandler.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace FluentMail\App\Hooks\Handlers;

class 
ExceptionHandler
{
    protected 
$handlers = [
        
'FluentMail\Includes\Support\ForbiddenException'   => 'handleForbiddenException',
        
'FluentMail\Includes\Support\ValidationException'  => 'handleValidationException'
    
];

    public function 
handle($e)
    {
        foreach (
$this->handlers as $key => $value) {
            if (
$e instanceof $key) {
                return 
$this->{$value}($e);
            }
        }
    }

    public function 
handleForbiddenException($e)
    {
        
wp_send_json_error([
            
'message' => $e->getMessage()
        ], 
$e->getCode() ?: 403);
    }

    public function 
handleValidationException($e)
    {
        
wp_send_json_error([
            
'message' => $e->getMessage(),
            
'errors'  => $e->errors()
        ], 
$e->getCode() ?: 422);
    }
}