Handling Additional HTTP Errors not handled in Laravel controller

by hello   Last Updated October 12, 2019 18:26 PM - source

If I have handled specific errors, 404 and 403, in a Laravel application but I also want to handle ALL other types of HTTP errors without overriding the defaults I set in place for 404 and 403. How can I achieve that in Laravel?

I have this piece of code that I am working with:

 public function render($request, Exception $exception)
    if ($exception){
        return response()->json([
            'status' => $exception->getStatusCode(),
            'error' => $exception->getMessage()
    return parent::render($request, $exception);

The code above returns the browser's 500 page for all errors, even for errors that were handled in the controller.

Controller where 403 is thrown:

public function update(ProfileUpdate $profileUpdate, $username)
   $admin = Misc::getAdminArray();
   if ($admin)     
        $profileUpdate->session()->flash('updated', 'Profile Updated!');
        return redirect()->route('someRoute');

Related Questions

http.get .catch not catching "wrong" url

Updated June 29, 2017 08:26 AM