0
votes

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?

1

1 Answers

1
votes

try this code. does this help!

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