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

Return JSON for InternalServerErrors #19

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Return JSON for InternalServerErrors #19

wants to merge 5 commits into from

Conversation

efe
Copy link
Contributor

@efe efe commented Apr 24, 2020

Issue: #7

@efe efe requested a review from baranugur April 24, 2020 11:54
@efe efe requested a review from a team April 24, 2020 12:12

INTERNAL_SERVER_ERROR_FALLBACK_MESSAGE = HIPO_DRF_SETTINGS.get(
"INTERNAL_SERVER_ERROR_FALLBACK_MESSAGE",
_('Our servers are unreachable at the moment. Please try again a few minutes later.')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to import gettext_lazy as _ for the translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, fixed.

@@ -1,7 +1,15 @@
from django.utils.translation import ugettext_lazy as _

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugettext_lazy is deprecated in Django 3.0 so it would be nice if we use gettext_lazy here for the sake of compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, fixed.

json_content_type = "application/json"
response = get_response(request)

if str(response.status_code).startswith("5") and request.content_type == json_content_type:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converts all 5XX responses to 500. Should not we check the full status code instead of checking the first character?

@efe efe marked this pull request as draft April 27, 2020 10:54
@yigitguler
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants