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

Error detail display format with non-JSON content-type responses #194

Closed
fmigneault opened this issue Jun 27, 2019 · 0 comments
Closed

Error detail display format with non-JSON content-type responses #194

fmigneault opened this issue Jun 27, 2019 · 0 comments
Assignees
Labels
enhancement Improvements in term of performance or behaviour
Milestone

Comments

@fmigneault
Copy link
Collaborator

When an error is returned and that the requested content type to be returned is HTML or plain text, the Exception Details section contains a string literal representation of the JSON object that would otherwise be displayed if asking application/json content-type.

Since the details are always expected to be a JSON structure, they should be dumped with "pretty-print" format using indents for better readability. Relevant code here:

try:
# directly output json
if outputType == CONTENT_TYPE_JSON:
json_type = "{}; charset=UTF-8".format(CONTENT_TYPE_JSON)
httpResponse = httpClass(body=jsonContent, content_type=json_type, **httpKWArgs)
# otherwise json is contained within the html <body> section
elif outputType == CONTENT_TYPE_HTML:
# add preformat <pre> section to output as is within the <body> section
htmlBody = "{}<br><h2>Exception Details</h2>" \
"<pre style='word-wrap: break-word; white-space: pre-wrap;'>{}</pre>" \
.format(httpClass.explanation, jsonContent)
httpResponse = httpClass(body_template=htmlBody, content_type=CONTENT_TYPE_HTML, **httpKWArgs)
# default back to plain text
else:
httpResponse = httpClass(body=jsonContent, content_type=CONTENT_TYPE_PLAIN, **httpKWArgs)

@fmigneault fmigneault added the enhancement Improvements in term of performance or behaviour label Jun 27, 2019
@fmigneault fmigneault self-assigned this Jun 27, 2019
@fmigneault fmigneault added this to the 1.x.x milestone Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements in term of performance or behaviour
Projects
None yet
Development

No branches or pull requests

1 participant