a Django-based indieweb.org site https://00dani.me/
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.

error.py 947B

123456789101112131415161718192021222324252627282930313233343536
  1. from django.http import JsonResponse
  2. from lemoncurry.middleware import ResponseException
  3. from typing import Optional
  4. def forbidden() -> ResponseException:
  5. return res('forbidden', 403)
  6. def unauthorized() -> ResponseException:
  7. return res('unauthorized', 401)
  8. def bad_req(msg: str) -> ResponseException:
  9. return res('invalid_request', msg=msg)
  10. def bad_type(type: str) -> ResponseException:
  11. msg = 'unsupported request type {0}'.format(type)
  12. return res('invalid_request', 415, msg)
  13. def bad_scope(scope: str) -> ResponseException:
  14. return res('insufficient_scope', 401, scope=scope)
  15. def res(error: str,
  16. status: Optional[int]=400,
  17. msg: Optional[str]=None,
  18. scope: Optional[str]=None):
  19. content = {'error': error}
  20. if msg is not None:
  21. content['error_description'] = msg
  22. if scope:
  23. content['scope'] = scope
  24. return ResponseException(JsonResponse(content, status=status))