mardi 13 novembre 2018

Improve the JWT Exception handling in json format data

Hi i am currently having a problem about JWT Exception JSON Message. The problem is when i checkIn but my token is expired and i received this

"message": "Token has expired",
    "exception": "Tymon\\JWTAuth\\Exceptions\\TokenExpiredException",
    "file": "C:\\Users\\Snowfox1991\\Desktop\\Capstone project\\back-end\\back-end\\vendor\\tymon\\jwt-auth\\src\\Claims\\Expiration.php",
    "line": 31,

But when i write the getAuthUser() in APIController, i use try catch this one

catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {

            return response()->json(['token_expired'=> 'Token is expired. Log in again!!']);

        } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {

            return response()->json(['token_invalid' => $e->getStatusCode()]);

        } catch (Tymon\JWTAuth\Exceptions\JWTException $e) {

            return response()->json(['token_absent' => $e->getStatusCode()]);

        }

And it still return the same as the original without the json format. Can i ask how to improve this exception using json format without handling the error like this. Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire