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

Django error formatter #392

Closed

Conversation

maxmorlocke
Copy link

@maxmorlocke maxmorlocke commented Jun 23, 2020

Ariadne's documentation is rightfully opinionated on the communication of exceptions from the server and strongly suggests protecting the errors key. It rightfully suggests replacing the default error formatter. To date, no preexisting sanely configured, easily overridable solution exists for communicating messages to users in the event of validation errors or other common problematic workflows (e.g. normal 401/403 type events).

In this PR, I have provided a simple solution that includes short, descriptive error messaging tied to HTTP-style messages for errors. I have also provided a path for user facing error messaging to be communicated. Communicating client-facing errors from server to client is a normal expectation, and providing a field exclusively for that allows for client-side developers to easily distinguish between GraphQL errors that are NOT user facing and ValidationErrors, etc. that most assuredly are.

Fair credit to the following post for providing some inspiration:

https://medium.com/@tarkus/validation-and-user-errors-in-graphql-mutations-39ca79cd00bf

The major difference is I use "non_field_errors" instead of "", which both makes intent more clear and follows standard django patterns.

Documentation PR: mirumee/ariadne-website#58

@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #392 into master will increase coverage by 0.02%.
The diff coverage is 98.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
+ Coverage   98.16%   98.18%   +0.02%     
==========================================
  Files         105      108       +3     
  Lines        5063     5233     +170     
==========================================
+ Hits         4970     5138     +168     
- Misses         93       95       +2     
Impacted Files Coverage Δ
ariadne/contrib/django/format_error.py 96.55% <96.55%> (ø)
ariadne/contrib/django/constants.py 100.00% <100.00%> (ø)
tests/test_django_error_formatting.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 905ec07...6540f2f. Read the comment docs.

@lgtm-com
Copy link

lgtm-com bot commented Jun 23, 2020

This pull request introduces 1 alert when merging 3749ec5 into 905ec07 - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@maxmorlocke
Copy link
Author

This should be ready for review

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.

1 participant