Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(responses): add new error responses #171

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bento_lib/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = bento_lib
version = 11.1.2
version = 11.2.0
authors = David Lougheed, Paul Pillot
author_emails = [email protected], [email protected]
6 changes: 6 additions & 0 deletions bento_lib/responses/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -87,6 +90,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)
9 changes: 8 additions & 1 deletion bento_lib/responses/flask_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import sys
import traceback

Expand All @@ -19,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",
Expand All @@ -37,7 +41,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):
Expand Down Expand Up @@ -84,6 +88,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)