app/Exceptions/Handler.php
/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
Render an exception into an HTTP response.
Render an exception into an HTTP response .
public function render($request, Exception $exception)
    {
        if ($exception instanceof \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException) {
            switch (get_class($exception->getPrevious())) {
                case \App\Exceptions\Handler::class:
                    return response()->json([
                        'success' => false,
                        'status'  => 401,
                        'error'   => 'Token is not provided',
                    ], $exception->getStatusCode());
                case \Tymon\JWTAuth\Exceptions\TokenExpiredException::class:
                    return response()->json([
                        'success' => false,
                        'status'  => 401,
                        'error'   => 'Token has expired',
                    ], $exception->getStatusCode());
                case \Tymon\JWTAuth\Exceptions\TokenInvalidException::class:
                case \Tymon\JWTAuth\Exceptions\TokenBlacklistedException::class:
                    return response()->json([
                        'success' => false,
                        'status'  => 401,
                        'error'   => 'Token is invalid',
                    ], $exception->getStatusCode());
                default:
                    break;
            }
        }
        return parent::render($request, $exception);
    }
public function render ( $ request , Exception $ exception ) { if ( $ exception instanceof \ Symfony \ Component \ HttpKernel \ Exception \ UnauthorizedHttpException ) { switch ( get_class ( $ exception -> getPrevious ( ) ) ) { case \ App \ Exceptions \ Handler :: class : return response ( ) -> json ( [ 'success' => false , 'status' => 401 , 'error' => 'Token is not provided' , ] , $ exception -> getStatusCode ( ) ) ; case \ Tymon \ JWTAuth \ Exceptions \ TokenExpiredException :: class : return response ( ) -> json ( [ 'success' => false , 'status' => 401 , 'error' => 'Token has expired' , ] , $ exception -> getStatusCode ( ) ) ; case \ Tymon \ JWTAuth \ Exceptions \ TokenInvalidException :: class : case \ Tymon \ JWTAuth \ Exceptions \ TokenBlacklistedException :: class : return response ( ) -> json ( [ 'success' => false , 'status' => 401 , 'error' => 'Token is invalid' , ] , $ exception -> getStatusCode ( ) ) ; default : break ; } } return parent :: render ( $ request , $ exception ) ; }
Render an exception into an HTTP response.
Render an exception into an HTTP response .