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 codes #4550

Merged
merged 9 commits into from
Oct 11, 2016
Merged

Error codes #4550

merged 9 commits into from
Oct 11, 2016

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Oct 10, 2016

Refs #3775.

TODO:

  • Document
  • Include shortcut on ValidationError to easily extract structured response.


* `.detail` - Return the textual description of the error.
* `.get_codes()` - Return the code identifier of the error.
* `.full_details()` - Retrun both the textual description and the code identifier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo Retrun

@tomchristie tomchristie merged commit a380250 into master Oct 11, 2016
@tomchristie tomchristie deleted the error-codes branch October 11, 2016 09:25
@johnraz
Copy link
Contributor

johnraz commented Oct 11, 2016

Awesome \o/
I now fully understand what you had in mind with the get_codes, get_details API.
That was an interesting piece 👍

@tomchristie
Copy link
Member Author

Yeah, takes out a little bit of pain for writing the custom exception handlers.

What would be great to see come out of this would be one or two third party packages for exception handlers that you can plug in with just a couple of lines of installation.

@tomchristie
Copy link
Member Author

Also pleased how this has come out - ErrorDetail can pretty much stay as an internal implementation detail (unless you're really doing something gnarly w/ modifying how serializers work). Instead you can just pass code to the exception, and we'll handle all the rest.

else:
msg = _('Must include "username" and "password".')
raise serializers.ValidationError(msg)
raise serializers.ValidationError(msg, code='authorization')
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the codes be different from each other here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily. We're not trying to identify every possible case, just a categorization. If uses want to have specific codes for those different cases then that's simple enough to do by customizing this.

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

Successfully merging this pull request may close these issues.

3 participants