Skip to content

Conversation

@lovelydinosaur
Copy link
Contributor

@lovelydinosaur lovelydinosaur 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

@lovelydinosaur lovelydinosaur merged commit a380250 into master Oct 11, 2016
@lovelydinosaur lovelydinosaur 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 👍

@lovelydinosaur
Copy link
Contributor 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.

@lovelydinosaur
Copy link
Contributor 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
Contributor 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.

4 participants