Raw response in JSON debug (#211)

This commit is contained in:
Michael Manfre 2022-12-20 03:19:00 -05:00 committed by GitHub
parent 2ccf2e683e
commit 84dbb51de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -23,6 +23,7 @@ class JsonViewer(FormView):
) )
def form_valid(self, form): def form_valid(self, form):
raw_result = ""
try: try:
response = async_to_sync(SystemActor().signed_request)( response = async_to_sync(SystemActor().signed_request)(
method="get", method="get",
@ -31,6 +32,7 @@ class JsonViewer(FormView):
except httpx.RequestError: except httpx.RequestError:
result = "Request Error" result = "Request Error"
else: else:
raw_result = response.text
if response.status_code >= 400: if response.status_code >= 400:
result = f"Error response: {response.status_code}\n{response.content}" result = f"Error response: {response.status_code}\n{response.content}"
else: else:
@ -39,4 +41,5 @@ class JsonViewer(FormView):
# Render results # Render results
context = self.get_context_data(form=form) context = self.get_context_data(form=form)
context["result"] = result context["result"] = result
context["raw_result"] = raw_result
return self.render_to_response(context) return self.render_to_response(context)

View File

@ -15,6 +15,11 @@
</div> </div>
</form> </form>
{% if result %} {% if result %}
<p>Canonacalized Response: (view source for raw)</p>
<div id="raw-json-result" style="display: none;">
{{ raw_result|escape }}
</div>
<pre>{{ result }}</pre> <pre>{{ result }}</pre>
{% endif %} {% endif %}
{% endblock %} {% endblock %}