-
Notifications
You must be signed in to change notification settings - Fork 6
Include more error data in HubspotClientError #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
1888951
1d49195
b7d94ed
68c0482
501cd7c
5a53d7d
a3ce40c
4e92c07
4c97e4d
9340ab8
80dbe71
0d940f5
4e9e7d1
31d35b6
74c7ce1
5e260fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,23 @@ class HubspotClientError(HubspotException): | |
| HubSpot deemed the request invalid. This represents an HTTP response code | ||
| of 40X, except 401 | ||
|
|
||
| :param unicode error_message: The error message returned by HubSpot | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for being pedantic but the order is wrong,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed :) |
||
| :param unicode request_id: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring should be updated with |
||
| :param dict optional error_data: The response data returned by HubSpot | ||
| :param int optional http_status_code: | ||
|
|
||
| """ | ||
| def __init__(self, msg, request_id): | ||
| def __init__(self, error_message, request_id, error_data=None, http_status_code=None): | ||
| if error_data and 'failureMessages' in error_data: | ||
| msg = u'{0} ({1!s})'.format(error_message, error_data['failureMessages']) | ||
| else: | ||
| msg = error_message | ||
| super(HubspotClientError, self).__init__(msg) | ||
|
|
||
| self.http_status_code = http_status_code | ||
| self.error_message = error_message | ||
| self.request_id = request_id | ||
| self.error_data = error_data | ||
|
|
||
|
|
||
| class HubspotAuthenticationError(HubspotClientError): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are explicitly including only the data that we need in the
_HUBSPOT_ERROR_RESPONSE_SCHEMAschema variable, since this commit is about adding more error data, it should be included in the schema so it can be validated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main point of this change is to expose the whole of
error_data, i.e. the whole of the error response body, to users of the library. The reason I want to do this is because I have code in my app that depends on the specifics of particular errors and HubSpot returns quite a few different things in the error response depending on which API endpoint is being used and what kind of error occurs so it would be very difficult to enumerate all of the possible properties that can occur inside error_data. In fact it would probably be impossible without access to HubSpot's internal code because we can only know about properties that we've seen in errors that we've encountered, and it'd probably be impossible for us to be confident that we'd triggered every single possible kind of error from every HubSpot API endpoint.Including the whole of error_data like this does break encapsulation but I think that the flexibility it gives to users of the library makes it worth it.
However, the code in HubspotClientError does explicitly look at the failureMessages property so I'll add that to the schema (once I've read up on voluptuous - I'm not familiar with it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added failureMessages to the schema in 672019f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankoid That sounds good to me, I believe at the time we even thought about doing something like this even thought it does indeed break encapsulation, but I completely understand the pain of working with Hubspot's API and their documentation...
I'll discuss with my colleagues this specific part of your implementation, but in my opinion, that's great. The only thing that I'm thinking is whether to make the schema for
failureMessagesa little bit more complete, but without checking their API documentation it's hard to tell what should the schema be, but since the idea is to have flexibility with whateverfailureMessagesyou get, I'd say that theOptional('failureMessages'): listshould suffice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @frankoid, could you give me some example output for the failureMessages or a way for me to replicate them, just so I can see the structure for it, I'm thinking that if we have a proper structure, we could use a Record to store it instead of just a list straight out of their response in order to have a higher level of abstraction.
I'll look at their Documentation in the interim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @LuRsT,
failureMessagesis used when there are errors during a bulk contact update - it contains the specific error that happened for each contact that failed to be updated (and the index of it so that you can figure out which of the contacts that you sent the error applies to).If you look in
test_client_error_responsethen you can see an example of whatfailureMessageslooks like. I think you can reproduce a similar error by using save_contacts (in hubspot-contacts) with a contact with no email address (or if that doesn't work then try a contact with the empty string as email address).If you think that giving failureMessages special treatment isn't the right way to go then I can remove it - client code would still be able to get at the failureMessages by poking around in error_data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @frankoid, sorry, I didn't mean the
failureMessages, I actually meant theerror_data, right now I don't have much time to deal with this (since we're in the middle a sprint right now) but I can tell you what I have in mind so you can think about this too.My "issue" with passing
error_datais that it would give too much low level data tohubspot-connectionclients, which is not great since it's a different level of abstraction. I see the ideal situation for this being a structure that we can pass to clients with the same level of abstraction asmessageandcode(meaning, in a proper structure) so that the client can deal with it accordingly, without having to parse through undocumented Hubspot data. Now, in order to do this, of course I'd need some time to check the format and all the error possibilities that Hubspot could get so that I can find an appropriate Schema for it.Once I have some time, that's what I'll do. I'll let you know once I resume working on your pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @LuRsT, I don't think that the detailed contents of error_data are documented. As an example,
failureMessagesisn't mentioned on the page that documents the resource that returns it.Without such documentation I'm not sure how you would compile a list of all of the error possibilities. You could try to do it by experimenting with the API, but there'd always be the possibility that a user of the library might come across an error situation (and corresponding HubSpot response) that your experiments hadn't uncovered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @frankoid, I imagined that that would be the case 😞, which means that a list of all error possibilities is not a possibility, but we could still get an idea of what kind os structure could we use to represent the information that Hubspot is passing, and if they really have a very unstructured way of displaying those errors (which I doubt) we could add something like
error_datanow, but I'd prefer to keep it as structured as possible, but trying to of course, avoid the situation that you described where a user gets something from Hubspot thathubpost-connectionis not ready for.It's not easy work, which is why I'll need to back to you once I have some proper time so we can decide on the next steps, feel free to explore possibilities and share, I'm more than happy to discuss alternative solutions 😃.