Skip to content

Commit 39a4b32

Browse files
aocneanutaylorotwell
authored andcommitted
Updates the Exception Handler in order to allow custom AuthenticationException message. (#21575)
Example use case: the user account gets disabled while the user is logged in the app and we want to logout the user and throw an exception with an appropriate message. Before the PR, in the handler the custom message is overwritten before sending the response.
1 parent fd88ff8 commit 39a4b32

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Illuminate/Foundation/Exceptions/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected function prepareException(Exception $e)
216216
protected function unauthenticated($request, AuthenticationException $exception)
217217
{
218218
return $request->expectsJson()
219-
? response()->json(['message' => 'Unauthenticated.'], 401)
219+
? response()->json(['message' => $exception->getMessage()], 401)
220220
: redirect()->guest(route('login'));
221221
}
222222

0 commit comments

Comments
 (0)