Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Return authentication exception for Laravel API 5.6
<?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 hanler 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
You can’t perform that action at this time.