Skip to content

chore: Replace raw HTTP status codes with http.HTTPStatus enums #1545

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions graphene_django/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import json
import re
from http import HTTPStatus

from django.db import connection, transaction
from django.http import HttpResponse, HttpResponseNotAllowed
Expand Down Expand Up @@ -195,7 +196,7 @@ def dispatch(self, request, *args, **kwargs):
status_code = (
responses
and max(responses, key=lambda response: response[1])[1]
or 200
or HTTPStatus.OK
)
else:
result, status_code = self.get_response(request, data, show_graphiql)
Expand All @@ -222,7 +223,7 @@ def get_response(self, request, data, show_graphiql=False):
if getattr(request, MUTATION_ERRORS_FLAG, False) is True:
set_rollback()

status_code = 200
status_code = HTTPStatus.OK
if execution_result:
response = {}

Expand All @@ -235,7 +236,7 @@ def get_response(self, request, data, show_graphiql=False):
if execution_result.errors and any(
not getattr(e, "path", None) for e in execution_result.errors
):
status_code = 400
status_code = HTTPStatus.BAD_REQUEST
else:
response["data"] = execution_result.data

Expand Down