UserNotAuthorizedException fired erroneously instead of AuthenticationFailedException
Issue found on December 5th 2020.
SDK Version: 0.7.1
OS Version: 11
Scope(s): App remote SDK
Steps to reproduce:
Error comes from Spotify's backend on periodic authentication calls. So no reliable reproduction steps from end-user's perspective.
Expected behavior:
The app remote SDK should always fire a AuthenticationFailedException on authentication failures resulting from network/service outages. This way clients can perform retry logic to keep the connection alive.
Actual behavior:
The SDK fires a UserNotAuthorizedException with the associated error message AUTHENTICATION_SERVICE_UNAVAILABLE. The description for this error found here states "Indicates the user did not authorize this client of App Remote to use Spotify on the users behalf. You need to make sure they approve app-remote-control scope first". This implies that retrying the connection without the user being prompted to re-approve the scope should not work, but in this case it did since it appeared to be caused by a normal service outage, making the resulting dropped connection and interruption to the user experience unnecessary.
Full error message below:
D/SpotifyConnection$Companion$getSpotifyAppRemote: com.spotify.android.appremote.api.error.UserNotAuthorizedException: {"message":"AUTHENTICATION_SERVICE_UNAVAILABLE"}
at com.spotify.android.appremote.api.LocalConnector.asAppRemoteException(LocalConnector.java:143)
at com.spotify.android.appremote.api.LocalConnector.access$000(LocalConnector.java:34)
at com.spotify.android.appremote.api.LocalConnector$1.onConnectionFailed(LocalConnector.java:117)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:162)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:95)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.access$900(AsyncTask.java:199)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: com.spotify.protocol.client.error.RemoteClientException: {"message":"AUTHENTICATION_SERVICE_UNAVAILABLE"}
at com.spotify.protocol.client.RemoteWampClient.getRemoteClientException(RemoteWampClient.java:139)
at com.spotify.protocol.client.RemoteWampClient.access$200(RemoteWampClient.java:16)
at com.spotify.protocol.client.RemoteWampClient$1.onAbort(RemoteWampClient.java:44)
at com.spotify.protocol.client.WampRouterImpl.routeAbort(WampRouterImpl.java:100)
at com.spotify.protocol.client.WampRouterImpl.route(WampRouterImpl.java:26)
at com.spotify.protocol.client.AppProtocolCommunicator.onData(AppProtocolCommunicator.java:78)
at com.spotify.android.appremote.internal.RemoteServiceIo.handleMessage(RemoteServiceIo.java:111)
at com.spotify.android.appremote.internal.RemoteServiceIo.access$000(RemoteServiceIo.java:45)
at com.spotify.android.appremote.internal.RemoteServiceIo$IncomingHandler.handleMessage(RemoteServiceIo.java:89)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)