-
Notifications
You must be signed in to change notification settings - Fork 208
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
Better validation error #150
Better validation error #150
Conversation
There are circumstances where the returned data may not have an 'Elements' key. In such cases, the upstream code bombs out and fails to report any useful error detail, see freakyboy3742/pyxero#78. This commit catches any KeyError in the problematic code expression, and stores the entire 'Message' value in the errors list as a fallback.
For validation errors, the value provided in 'Message' is not actually very helpful. The important information is in the 'ValidationErrors' values. To make the main exception message more useful, I have appended the exception 'problem' to the main message, for JSON HTTP 400 responses. See freakboy3742#129
I'm not really sure what this is doing? |
Please review discussion at #129 for full details, but currently the XeroBadRequest exception for validation errors ends up with a useless 'message' attribute. This PR appends some detail of the validation problem in the main message, making it easier to troubleshoot validation problems. Sorry for the noise in the commit history, that's due to some merges I made on the 'master' branch of my fork. |
Can we go a little further and have something like: XeroAPIError: BadFormatting (invoice x had y, and 5 other issues) |
We can't really do the "invoice x" part, because the Xero API doesn't give us that information. See https://developer.xero.com/documentation/getting-started/http-response-codes/#title3 But I do think the "... and z other issues" bit has merit, I'll update my branch with that addition. |
If there are multiple errors in a HTTP 400 response, we include the first one in the main message, and also mention how many other errors there are.
Thanks @aidanlister ! |
Thanks for this @direvus! I was getting validation errors and running into the problem of the exception not providing any useful information; I've just updated to |
That's awesome @jordanmkoncz, thanks for the feedback! |
Include details of validation errors in the main exception message, per #129