From f44dda5942ad688c4a9126c593db5f40cd3b3bba Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 3 Jan 2024 15:15:18 -0500 Subject: [PATCH 1/2] feat(responses): add new error responses --- bento_lib/package.cfg | 2 +- bento_lib/responses/errors.py | 3 +++ bento_lib/responses/flask_errors.py | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bento_lib/package.cfg b/bento_lib/package.cfg index e7c2d6f..9cc1286 100644 --- a/bento_lib/package.cfg +++ b/bento_lib/package.cfg @@ -1,5 +1,5 @@ [package] name = bento_lib -version = 11.1.2 +version = 11.2.0 authors = David Lougheed, Paul Pillot author_emails = david.lougheed@mail.mcgill.ca, paul.pillot@computationalgenomics.ca diff --git a/bento_lib/responses/errors.py b/bento_lib/responses/errors.py index 23efe13..46238b3 100644 --- a/bento_lib/responses/errors.py +++ b/bento_lib/responses/errors.py @@ -87,6 +87,9 @@ def http_error( unauthorized_error = _e(401) forbidden_error = _e(403) not_found_error = _e(404) +not_acceptable_error = _e(406) +request_timeout_error = _e(408) +range_not_satisfiable_error = _e(416) internal_server_error = _e(500) not_implemented_error = _e(501) diff --git a/bento_lib/responses/flask_errors.py b/bento_lib/responses/flask_errors.py index d384e78..aa975f8 100644 --- a/bento_lib/responses/flask_errors.py +++ b/bento_lib/responses/flask_errors.py @@ -1,3 +1,4 @@ +import logging import sys import traceback @@ -37,7 +38,7 @@ def flask_error_wrap_with_traceback(fn: Callable, *args, **kwargs) -> Callable: service_name = kwargs.pop("service_name", "Bento Service") - logger = kwargs.pop("logger", None) + logger: logging.Logger | None = kwargs.pop("logger", None) authz: MarkAuthzDoneType | None = kwargs.pop("authz", None) def handle_error(e): @@ -84,6 +85,9 @@ def _flask_error(code: int) -> Callable: flask_unauthorized_error = _flask_error(401) flask_forbidden_error = _flask_error(403) flask_not_found_error = _flask_error(404) +flask_not_acceptable_error = _flask_error(406) +flask_request_timeout_error = _flask_error(408) +flask_range_not_satisfiable_error = _flask_error(416) flask_internal_server_error = _flask_error(500) flask_not_implemented_error = _flask_error(501) From a40064c21d30d2e4bb30ef901015371e1854d1ee Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 3 Jan 2024 15:18:30 -0500 Subject: [PATCH 2/2] missing exports --- bento_lib/responses/errors.py | 3 +++ bento_lib/responses/flask_errors.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/bento_lib/responses/errors.py b/bento_lib/responses/errors.py index 46238b3..93b3663 100644 --- a/bento_lib/responses/errors.py +++ b/bento_lib/responses/errors.py @@ -12,6 +12,9 @@ "unauthorized_error", "forbidden_error", "not_found_error", + "not_acceptable_error", + "request_timeout_error", + "range_not_satisfiable_error", "internal_server_error", "not_implemented_error", diff --git a/bento_lib/responses/flask_errors.py b/bento_lib/responses/flask_errors.py index aa975f8..8762b7a 100644 --- a/bento_lib/responses/flask_errors.py +++ b/bento_lib/responses/flask_errors.py @@ -20,6 +20,9 @@ "flask_unauthorized_error", "flask_forbidden_error", "flask_not_found_error", + "flask_not_acceptable_error", + "flask_request_timeout_error", + "flask_range_not_satisfiable_error", "flask_internal_server_error", "flask_not_implemented_error",