Skip to content

Commit

Permalink
Update to make it easier to get problem detail
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Feb 21, 2024
1 parent cd61b52 commit aca047c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 3 additions & 4 deletions core/app_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ def handle(self, exception: Exception) -> Response | HTTPException:

# Try to turn the exception into a useful HTTP error response.
if isinstance(exception, (RemoteIntegrationException, ProblemError)):
if isinstance(exception, RemoteIntegrationException):
document = exception.as_problem_detail_document(self.debug)
else:
document = exception.problem_detail
# This exception can be turned directly into a problem
# detail document.
document = exception.problem_detail

if not self.debug:
document.debug_message = None
Expand Down
4 changes: 4 additions & 0 deletions core/util/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def as_problem_detail_document(self, debug):
debug_message=self.document_debug_message(debug),
)

@property
def problem_detail(self):
return self.as_problem_detail_document(debug=False)


class BadResponseException(RemoteIntegrationException):
"""The request seemingly went okay, but we got a bad response."""
Expand Down
10 changes: 10 additions & 0 deletions tests/core/util/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ def test_as_problem_detail_document(self):
== document.debug_message
)

# We can also use the problem_detail property to get the same result
document_from_property = exception.problem_detail
assert document.uri == document_from_property.uri
assert document.title == document_from_property.title
assert document.status_code == document_from_property.status_code

# But problem_detail is always the non-debug version, so the debug_message is not present
assert document.debug_message != document_from_property.debug_message
assert document_from_property.debug_message is None


class TestRequestTimedOut:
def test_as_problem_detail_document(self):
Expand Down

0 comments on commit aca047c

Please sign in to comment.