Skip to content

Instantly share code, notes, and snippets.

@farindra
Created April 4, 2021 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farindra/5978787beea4c861b242a30cd27dac39 to your computer and use it in GitHub Desktop.
Save farindra/5978787beea4c861b242a30cd27dac39 to your computer and use it in GitHub Desktop.
Lumen Jwtauth Part 1 - Error Handler
public function render($request, Throwable $exception)
{
/* only run if debug is turn off */
if ( !env('APP_DEBUG', true) ) {
/* handling 404 exception */
if($exception instanceof NotFoundHttpException){
return response()->json([
'error' => 'Not Found',
])->setStatusCode(404);
}
/* handling 500 exception */
return response()->json([
'error' => 'server problem',
'error_info' => $exception->getMessage(),
'data' => $exception->getTraceAsString(),
])->setStatusCode(500);
}
return parent::render($request, $exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment