Last active
March 10, 2021 10:29
-
-
Save lucagrandicelli/0570fa8d6292c171f4e3c2796d2bb7bd to your computer and use it in GitHub Desktop.
Laravel 8 API/Web Exception Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register the exception handling callbacks for the application. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->reportable(function (Throwable $e) {}); | |
// reportable | |
$this->renderable(function (NotFoundHttpException $e, Request $request) { | |
if ($request->wantsJson()) { | |
return response(['errorjson' => $e->getMessage()], $e->getCode() ?: 404); | |
} else { | |
return response(['errorweb' => $e->getMessage()], $e->getCode() ?: 404); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment