Question: I want to throw a custom exception if the variable is null and return it as JSON.
I've tried like this:

**Controller**

```php
try {
    $check_api_key = $attendance_libraries->check_api_key($this->request);
    if ($check_api_key == null) {
        throw new NullException(false, 'API Key Not Found', null, 500);
    }
} catch (NullException $e) {
    return $e;
} catch (\Exception $e) {
    // do something else           
}

```

**Custom Exception**

```
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Response;

class NullException extends Exception
{
    public $is_success;
    public $message;
    public $code;
    public $data;

    public function __construct($is_success, $message, $code, $data = null, Exception $previous = NULL)
    {
        $this->is_success = $is_success;
        $this->message = $message;
        $this->code = $code;
        $this->data = $data;
    }

    public function render()
    {
        return response()->json([
            'success' => $this->is_success,
            'message' => $this->message,
            'data' => $this->data,
        ], $this->code);
    }
}

```

But when I am trying to test it using postman, the return I got is not the same as I wrote in NullException. It becomes like this:
[![Postman response](https://i.stack.imgur.com/QpFNl.png)](https://i.stack.imgur.com/QpFNl.png)

Answer: 
You're seeing this error because of an inline event handler and will need to define `script-src-elem` in your CSP policy.
I did a little research and found out that those errors are due to an inline event handler. You will need to define `script-src-elem` in your CSP policy.

You can find more about it from [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src-elem)