pushE
pushE

Reputation: 414

JWT signature failed errors are not coming as JSON errors in SLIM

I am using Firebase JWT in one of my SLIM framework apps for RESTFul api. But all the JWT errors occur as slim app error rather than throwing back json errors ,which i can return to user. Like in image below enter image description here SignatureInvalidException

Can you help how can i display JWT errros in json format ,so that my restful api return that json error to user.

Upvotes: 0

Views: 194

Answers (1)

Zamrony P. Juhara
Zamrony P. Juhara

Reputation: 5262

If you need to output error as JSON, you need to handle the exception. For example:

try {
    //do something when everything is OK
} catch (\Firebase\JWT\SignatureInvalidException $e) {
    return $response->withJson(
       (object) [
          'error' => true,
          'code' => $e->getCode(),
          'message' => $e->getMessage()
       ],
       500
    );
}

Upvotes: 1

Related Questions