Skip to content

Conversation

tetienne
Copy link
Collaborator

See #35

@tetienne tetienne force-pushed the fix/handle_error_without_json branch from 7ad8a9c to e2f3a1b Compare August 14, 2020 21:34
@tetienne tetienne requested a review from iMicknl August 15, 2020 14:48
pyhoma/client.py Outdated
result = await response.json()
except ContentTypeError:
body = await response.text()
raise Exception(body or "Something bad happened")
Copy link
Owner

Choose a reason for hiding this comment

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

For now raising an exception is fine, until we understand what the content is. Then I would like to handle it in a better way.

Can we change Something bad happened to a bit more descriptive error perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think about adding the URL, payload and status code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed with a more explicit message

@tetienne
Copy link
Collaborator Author

@iMicknl @vlebourl I've ease again the error management logic. With the previous process, when a command on a wrong deviceurl was sent, the returned error was ignored. It's an error 400 with the following JSON: `{'errorCode': 'INVALID_FIELD_VALUE', 'error': 'Invalid device URL : foo'}

@tetienne tetienne marked this pull request as draft August 19, 2020 07:25
@tetienne tetienne force-pushed the fix/handle_error_without_json branch from bb1b5d6 to df6ef84 Compare August 20, 2020 06:55
pyhoma/client.py Outdated
except JSONDecodeError:
body = await response.text()
raise Exception(
f"Something bad happened when requesting {response.url}. {body}"
Copy link
Owner

Choose a reason for hiding this comment

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

Will this actually fix #35? Or was the fix to add content_type=None, since the TaHoma API sometimes adds the wrong mimetype?

Copy link
Collaborator Author

@tetienne tetienne Aug 24, 2020

Choose a reason for hiding this comment

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

The one fixing #35 is content_type=None. It avoids aiohttp to look for the mime-type. It's why now I have to check for JSONDecodeError in case JSON is not returned.

Copy link
Owner

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

Could we split this PR in two? One PR that contains the JSON decoding fix for #35 and the NotAuthenticatedException + another PR adding all the Event Listener logic?

I am not sure yet if I like the behaviour where we hardcode all the event handling in the api library, instead of the clients leveraging this library. I rather add some helper functions in this library, available for clients to consume.

Comment on lines +121 to +131
@staticmethod
def _update_available(devices: Dict[str, Device], event: Event) -> None:
if event.name == "DeviceAvailableEvent" and event.deviceurl:
devices[event.deviceurl].available = True
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@iMicknl You should recognize this code :)

@tetienne
Copy link
Collaborator Author

@iMicknl No problem, I can remove the fetch_device method. Do you want me also remove the retry logic?
Having some logic within the library around the event, it's IMO something good. It will avoid the clients to recreate the wheel each time. But we can rework what I did in another PR as you suggest.

@iMicknl
Copy link
Owner

iMicknl commented Aug 26, 2020

@iMicknl No problem, I can remove the fetch_device method. Do you want me also remove the retry logic?
Having some logic within the library around the event, it's IMO something good. It will avoid the clients to recreate the wheel each time. But we can rework what I did in another PR as you suggest.

It would be great if you could split them in 3 for now.

  1. fix JSON decode issue (Handle 'Attempt to decode JSON with unexpected mimetype: ' exceptions #41)
  2. retry logic
  3. reconnect event listener etc.

@tetienne tetienne force-pushed the fix/handle_error_without_json branch from 0c9e6dc to 7b3bda1 Compare August 27, 2020 07:47
@iMicknl
Copy link
Owner

iMicknl commented Sep 14, 2020

@tetienne can we close this one? I think we cherry picked all your changes in different PR's?

@iMicknl iMicknl closed this Sep 21, 2020
KhealthDavid added a commit to KhealthDavid/python-graphql-client that referenced this pull request May 2, 2021
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.

3 participants