Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make staging repository operations retry on failure #17

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Keep the former HttpClientUtil.create signature
So that it still throws when something goes wrong, and users aren't
surprised with the new behavior of createResponse
  • Loading branch information
alexarchambault committed Sep 27, 2023
commit 94148869390b9ffdf77be0866e1f20ca5705d286
10 changes: 9 additions & 1 deletion publish/src/coursier/publish/sonatype/HttpClientUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ private[sonatype] final case class HttpClientUtil(
}
}

def create(
def create(url: String, post: Option[Array[Byte]] = None, isJson: Boolean = false): Unit = {
val resp = createResponse(url, post, isJson)
if (resp.code.code != 201)
throw new Exception(
s"Failed to get $url (http status: ${resp.code.code}, response: ${Try(new String(resp.body, StandardCharsets.UTF_8)).getOrElse("")})"
)
}

def createResponse(
url: String,
post: Option[Array[Byte]] = None,
isJson: Boolean = false
Expand Down
2 changes: 1 addition & 1 deletion publish/src/coursier/publish/sonatype/SonatypeApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ final case class SonatypeApi(
val body = postBody(writeToArray(StagedRepositoryRequest(description, repositoryId)))
@tailrec
def sendRequest(attempt: Int): Unit = {
val resp = clientUtil.create(url, post = Some(body), isJson = true)
val resp = clientUtil.createResponse(url, post = Some(body), isJson = true)

if (!resp.code.isSuccess) {
if (attempt >= stagingRepoRetries)
Expand Down