Skip to content

Commit

Permalink
ApiClient: print stack trace when retry fails
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 2, 2024
1 parent 702b184 commit a1c533e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions maestro-cli/src/main/java/maestro/cli/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import okio.ForwardingSink
import okio.IOException
import okio.buffer
import java.io.File
import java.net.SocketException
import java.nio.file.Path
import java.util.UUID
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -291,12 +292,13 @@ class ApiClient(

val body = bodyBuilder.build()

fun retry(message: String): UploadResponse {
fun retry(message: String, e: Throwable? = null): UploadResponse {
if (completedRetries >= maxRetryCount) {
e?.printStackTrace()
throw CliError(message)
}

PrintUtils.message("$message, retrying...")
PrintUtils.message("$message, retrying (${completedRetries+1}/$maxRetryCount)...")
Thread.sleep(BASE_RETRY_DELAY_MS + (2000 * completedRetries))

return upload(
Expand Down Expand Up @@ -331,9 +333,10 @@ class ApiClient(
.post(body)
.build()

throw SocketException("Test")
client.newCall(request).execute()
} catch (e: IOException) {
return retry("Upload failed due to socket exception")
return retry("Upload failed due to socket exception", e)
}

response.use {
Expand Down

0 comments on commit a1c533e

Please sign in to comment.