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 5878d3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 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 @@ -330,10 +332,10 @@ class ApiClient(
.url("$baseUrl/v2/upload")
.post(body)
.build()

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 5878d3b

Please sign in to comment.