# fluent-support/2.2.0/app/Hooks/Handlers/ExceptionHandler.php

Fluent Support – Helpdesk &amp; Customer Support Ticket System, version 2.2.0. 60 lines.

- Page: https://pluginprobe.com/plugins/fluent-support/2.2.0/code/app/Hooks/Handlers/ExceptionHandler.php
- Raw: https://pluginprobe.com/plugins/fluent-support/2.2.0/raw/app/Hooks/Handlers/ExceptionHandler.php
- Modified: 2021-11-12T14:57:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-support/2.2.0/code/app/Hooks/Handlers/ExceptionHandler.php#L10-L20`.

```php
<?php

namespace FluentSupport\App\Hooks\Handlers;

class ExceptionHandler
{
    protected $handlers = [
        'InvalidArgumentException' => 'handleInvalidArgumentException',
        'FluentSupport\Framework\Foundation\ForbiddenException' => 'handleForbiddenException',
        'FluentSupport\Framework\Validator\ValidationException' => 'handleValidationException',
        'FluentSupport\Framework\Foundation\UnAuthorizedException' => 'handleUnAuthorizedException',
        'FluentSupport\Framework\Database\Orm\ModelNotFoundException' => 'handleModelNotFoundException',
    ];

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

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

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

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

    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);
    }
}

```
