Created
April 4, 2021 23:34
-
-
Save farindra/5978787beea4c861b242a30cd27dac39 to your computer and use it in GitHub Desktop.
Lumen Jwtauth Part 1 - Error 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
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