Jishad
Jishad

Reputation: 2965

Override Payload Exception of Laravel

I am getting an exception of payload is invalid when editing the encrypted ID as manually.

I need to make as a json response for this exception like

   ['status=>400,'message'=>'The Payload is invalid']

When working with API's I am using the encrypted form of ID and I getting the HTML type exception for Payload is invalid. I wan to to change it to the json format for avoiding type issue in Mobile team.

enter image description here

Upvotes: 0

Views: 829

Answers (1)

Khurram Shahzad
Khurram Shahzad

Reputation: 167

You can go to app/Exceptions/Handler.php. In render method.

public function render($request, Exception $exception)
{
    if ($exception instanceof \Illuminate\Contracts\Encryption\DecryptException) {

        return response()->json([
           'message' => 'The Payload is invalid'
        ], 400);

    }

    return parent::render($request, $exception);
}

Upvotes: 2

Related Questions