Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

engrlaravel's avatar

API Authentication, return error message

I am using api_token for authentication in laravel api using this document

https://laravel.com/docs/6.x/api-authentication

when i post my token with Bearer in postman, & the token is wrong, instead of error message i am getting

Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined.

How i can get unauthorized error message?

0 likes
3 replies
James_Moore's avatar

@engrlaravel It might be a good idea to set a break point in app\Exceptions\Hander.php render method, to see whats happening when it hits here to cause what should be a authorization exception to throw a NotFound Exception. It might be missing the code to check for a Authorization exception.

    public function render($request, Exception $exception)
    {
        if ($exception instanceof AuthorizationException) {
            $exception = new \App\Exceptions\AuthorizationException(403, $exception->getMessage(), $exception);
    }
    //....
engrlaravel's avatar

I was surprised, when i changed Accept to application/json in postman,it worked well

Please or to participate in this conversation.