Last active
November 25, 2019 07:47
-
-
Save thearyanahmed/617e8e2ef7df01244474305dca0ded7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// In the App\Exceptions\Handler.php class,update the `render` function as following | |
$exceptionCode = null; | |
if(config('app.env') !== 'production') { | |
$res = [ | |
'file' => $exception->getFile(), | |
'line' => $exception->getLine(), | |
'previous' => $exception->getPrevious(), | |
'stack_trace_string' => $exception->getTraceAsString(), | |
'exception_code' => $exception->getCode(), | |
]; | |
} | |
if($exception instanceof ValidationException) { | |
$errors = $exception->errors(); | |
$res['errors'] = []; | |
foreach($errors as $error) { | |
array_push($res['errors'],implode('',$error)); | |
} | |
$exceptionCode = 406; | |
} else { | |
$exceptionCode = $exception->getCode(); | |
} | |
$res['message'] = $exception->getMessage(); | |
return response()->json($res,$exceptionCode); | |
// Works for `throw new $exception` and `form valdiations/requests`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment