A multipurpose python flask API server and administration SPA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
641 B

  1. from functools import wraps
  2. from typing import Callable, Any
  3. from flask import jsonify, Response
  4. from corvus.api.model import APIResponse
  5. def return_json(func: Callable) -> Callable:
  6. """
  7. If an Response object is not returned, jsonify the result and return it
  8. :param func:
  9. :return:
  10. """
  11. @wraps(func)
  12. def decorate(*args: list, **kwargs: dict) -> Any:
  13. result = func(*args, **kwargs)
  14. if isinstance(result, Response):
  15. return result
  16. if isinstance(result, APIResponse):
  17. return jsonify(result.payload), result.status
  18. return jsonify(result)
  19. return decorate