Skip to content

Commit

Permalink
Merge pull request apache#28 from riskive/update-status-error
Browse files Browse the repository at this point in the history
Update status error
  • Loading branch information
rguerraZero committed Sep 7, 2023
2 parents 4001071 + bc18d65 commit 8540b59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zf_integration/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.
import logging

from jwt import ExpiredSignatureError
from typing import Any, Dict

from flask import request, Response, jsonify, make_response
from flask_appbuilder import expose
from marshmallow import ValidationError
Expand Down Expand Up @@ -95,6 +95,8 @@ def get_info(self) -> Response:
'custom_dashboards': custom_dashboards['dashboards'],
}
return make_response(jsonify(respond), 200)
except ExpiredSignatureError:
return self.response_401()
except ValidationError as error:
return self.response_400(message=error.messages)

Expand Down
4 changes: 4 additions & 0 deletions zf_utils/jwt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import jwt
from jwt import ExpiredSignatureError


from flask import current_app, Request
from typing import Any, Dict
Expand All @@ -17,6 +19,8 @@ def parse_jwt_from_request(cls, req: Request) -> Dict[str, Any]:
raise Exception("Token not present")
try:
return jwt.decode(token, _jwt_secret, algorithms=["RS512"])
except ExpiredSignatureError as ex:
raise ex
except Exception as ex:
logger.warning("Parse jwt failed", exc_info=True)
raise Exception("Failed to parse token") from ex

0 comments on commit 8540b59

Please sign in to comment.