An ebook/comic library service and web client
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
619 B

  1. from functools import wraps
  2. from typing import Callable
  3. from flask import jsonify, Response
  4. from atheneum.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, **kwargs):
  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