Last active
February 28, 2020 04:59
-
-
Save full-stack-king/b53a702abc836559e1222cafe9735c09 to your computer and use it in GitHub Desktop.
Return authentication exception for Laravel API 5.6
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
<?php | |
/** | |
* Render an exception into an HTTP response. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Exception $exception | |
* @return \Illuminate\Http\Response | |
*/ | |
public function render($request, Exception $exception) | |
{ | |
// custom exception handler for unauthenticated requests | |
if ($exception instanceof AuthenticationException) { | |
return response()->json([ | |
'errors' => [ | |
'status' => 401, | |
'message' => 'Unauthenticated', | |
] | |
], 401); | |
} | |
// default handler | |
return parent::render($request, $exception); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment