awslabs / aws-mobile-appsync-sdk-android

Android SDK for AWS AppSync.
https://docs.amplify.aws/sdk/api/graphql/q/platform/android/
Apache License 2.0
105 stars 58 forks source link

Subscription initialization throws "Invalid message type string" exception when token has expired #246

Open JakubGongol opened 4 years ago

JakubGongol commented 4 years ago

Describe the bug The issue happens when app tries to initialize subscription with an expired token. WebSocketConnectionManager.processJsonMessag(websocket, message) gets as message:

{"type":"connection_error","payload":{"errors":[{"errorType":"Unauthorized","errorCode":401}]}}

which cannot be parsed because connection_error does not exists in MessageType enum. So the result is IllegalArgumentException("Invalid message type string");

To Reproduce Steps to reproduce the behavior: Provide expired token during subscription initialization.

Expected behavior New MessageType suitable to code 401 should be added so IllegalArgumentException("Invalid message type string"); won't be thrown. And subscription request should be repeated with the refreshed token.

Environment(please complete the following information):

Device Information (please complete the following information):

desokroshan commented 4 years ago

@JakubGongol Thanks for reporting this. I will look into it and provide an update.

JakubGongol commented 4 years ago

Hi @desokroshan any update about this issue, please?

jamesonwilliams commented 4 years ago

Hi @JakubGongol - we would like to fix this issue, but don't have a fix date for it, yet.

We have code for realtime subscriptions in two code bases: this production AppSync SDK, and our in-development Amplify Android project. I believe we are correctly handling the "connection_error" message type in the new code base.

We would like to have this functionality into the AppSync SDK, too. To fix this, some changes are needed in the WebSocketConnectionManager. Would certainly review a PR, if one comes in before we can fix this.