Я использую python flask restful для создания Rest api.
В полученной документации по спецификации открытого API есть несколько кодов ошибок http, которые необходимо обработать, как показано ниже:
400 Bad request.
The text is missing.
The body cannot be structured
401 Unauthorized.
The required bearer token is missing.
403 Forbidden.
The bearer token is invalid.
The claims in the bearer token are insufficient.
500 Internal Server Error.
The application failed to process the request.
Я выполнил все вышеперечисленные критерии, как указано ниже:
if bearer_token:
if check_digital_signature_criteria(bearer_token, public_key):
if connexion.request.is_json:
body_data = request.get_json()
response = do_something(body_data)
return response, 200
else:
return {"Bad request": "The body cannot be structured"}, 400
else:
return {"Forbidden": "The bearer token is invalid."}, 403
else:
return {"Unauthorized": "The required bearer token is missing."}, 401
except Exception as exception:
error = create_500_common_message_json()
return json.default(error), 500
Пожалуйста, дайте мне знать, если есть какой-либо эффективный способ обработки / реализации всех вышеперечисленных кодов ошибок при разработке флакона Python?