Elie
Elie

Reputation: 321

How to intercept laravel http error responses

I am trying to handle all errors thrown by a Laravel project

I overrode some of the code in the file app\Exception\Handler.php

public function render($request, Exception $e)
{
    $err = New Response;
    $err->Response=0;
    $err->Message = $e;
    return json_encode($err);
    //return parent::render($request, $e);
}

I commented the render function and tried to return an instance of my custom error class

However this did not work, because i am returning a different type (response does not extend ExceptionHandler

Is there a way to do what i want?

Upvotes: 0

Views: 1444

Answers (1)

Shailesh Ladumor
Shailesh Ladumor

Reputation: 7242

try this code. does this help!

   public function render($request, Exception $e)
        {
               return \Response::json([
                        'success' => false,
                        'message' => $e->getMessage(),
                  ], $e->getCode());
               } 
         }

Upvotes: 1

Related Questions