From 12903a29ff15659c1c046da72e08122492cc0f19 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Thu, 3 Nov 2022 21:42:24 -0700 Subject: [PATCH] Fixes #309: Handle 404 upon repository drop (#327) * Fixes #309: Handle 404 upon repository drop * Fix message --- .../xerial/sbt/sonatype/SonatypeClient.scala | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala index f4f005dd..69d94cb9 100644 --- a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala +++ b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala @@ -220,14 +220,20 @@ class SonatypeClient( def dropStage(currentProfile: StagingProfile, repo: StagingRepositoryProfile): Response = { info(s"Dropping staging repository $repo") - val ret = httpClient.call[Map[String, StageTransitionRequest], Response]( - Http.POST(s"${pathPrefix}/staging/profiles/${repo.profileId}/drop"), - newStageTransitionRequest(currentProfile, repo) - ) - if (ret.statusCode != HttpStatus.Created_201.code) { - throw SonatypeException(STAGE_FAILURE, s"Failed to drop the repository. [${ret.status}]: ${ret.contentString}") + try { + val ret = httpClient.call[Map[String, StageTransitionRequest], Response]( + Http.POST(s"${pathPrefix}/staging/profiles/${repo.profileId}/drop"), + newStageTransitionRequest(currentProfile, repo) + ) + if (ret.statusCode != HttpStatus.Created_201.code) { + throw SonatypeException(STAGE_FAILURE, s"Failed to drop the repository. [${ret.status}]: ${ret.contentString}") + } + ret + } catch { + case e: HttpClientException if e.status == HttpStatus.NotFound_404 => + warn(s"Staging repository ${repo.profileId} is not found. It might already have been dropped: ${e.getMessage}") + e.response.toHttpResponse } - ret } private def newStageTransitionRequest(