@@ -74,24 +74,31 @@ public Response send(@NotNull String method, @NotNull String suffix, @Nullable H
7474 IOException lastEx ;
7575 do {
7676 try {
77- return session .client ().newCall (buildRequest (method , suffix , headers , body )).execute ();
77+ Response resp = session .client ().newCall (buildRequest (method , suffix , headers , body )).execute ();
78+ if (resp .code () == 503 ) {
79+ lastEx = new StatusCodeException (resp );
80+ continue ;
81+ }
82+
83+ return resp ;
7884 } catch (IOException ex ) {
7985 lastEx = ex ;
8086 }
81- } while (tries -- > 0 );
87+ } while (tries -- > 1 );
8288
8389 throw lastEx ;
8490 }
8591
8692 @ NotNull
8793 public Response send (@ NotNull String method , @ NotNull String suffix , @ Nullable Headers headers , @ Nullable RequestBody body ) throws IOException , MercuryClient .MercuryException {
88- return send (method , suffix , headers , body , 0 );
94+ return send (method , suffix , headers , body , 1 );
8995 }
9096
9197 public void putConnectState (@ NotNull String connectionId , @ NotNull Connect .PutStateRequest proto ) throws IOException , MercuryClient .MercuryException {
9298 try (Response resp = send ("PUT" , "/connect-state/v1/devices/" + session .deviceId (), new Headers .Builder ()
9399 .add ("X-Spotify-Connection-Id" , connectionId ).build (), protoBody (proto ), 5 /* We want this to succeed */ )) {
94- if (resp .code () != 200 ) LOGGER .warn (String .format ("PUT %s returned %d" , resp .request ().url (), resp .code ()));
100+ if (resp .code () != 200 )
101+ LOGGER .warn (String .format ("PUT %s returned %d. {headers: %s}" , resp .request ().url (), resp .code (), resp .headers ()));
95102 }
96103 }
97104
0 commit comments