Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel 8 API/Web Exception Handler
<?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