From d0ac3e28aeefb6ff550d7faf78d4fd8a6f305bf7 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 27 May 2024 12:12:09 +0100 Subject: [PATCH] copy old S3Exception code from Alpakka --- LICENSE.txt | 4 +++ .../core/database/s3/S3Exception.scala | 33 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index 933501710f8..1781c2d8021 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -213,6 +213,10 @@ Spray Caching 1.3.4 (io.spray:spray-caching_2.11:1.3.4 - http://spray.io/documen License included at licenses/LICENSE-spray.txt, or https://github.com/spray/spray/blob/master/LICENSE Copyright (C) 2011-2015 the spray project +common/scala/src/main/scala/org/apache/openwhisk/core/database/s3/S3Exception.scala +is based on https://github.com/akka/alpakka/blob/v1.0.2/s3/src/main/scala/akka/stream/alpakka/s3/S3Exception.scala + Copyright (C) 2016-2019 Lightbend Inc. + This product bundles the files gradlew and gradlew.bat from Gradle v5.5 which are distributed under the Apache License, Version 2.0. For details see ./gradlew and ./gradlew.bat. diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/database/s3/S3Exception.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/database/s3/S3Exception.scala index cc64f543f5d..ff9fdac0817 100644 --- a/common/scala/src/main/scala/org/apache/openwhisk/core/database/s3/S3Exception.scala +++ b/common/scala/src/main/scala/org/apache/openwhisk/core/database/s3/S3Exception.scala @@ -15,6 +15,37 @@ * limitations under the License. */ + /* + * Copyright (C) 2016-2019 Lightbend Inc. + */ + package org.apache.openwhisk.core.database.s3 -class S3Exception(msg: String) extends Exception(msg) +import scala.util.Try +import scala.xml.{Elem, XML} + +/** + * Exception thrown by S3 operations. + * + * Copied from https://github.com/akka/alpakka/blob/v1.0.2/s3/src/main/scala/akka/stream/alpakka/s3/S3Exception.scala + */ +private[s3] class S3Exception(val code: String, val message: String, val requestId: String, val hostId: String) + extends RuntimeException(message) { + + def this(xmlResponse: Elem) = + this((xmlResponse \ "Code").text, + (xmlResponse \ "Message").text, + (xmlResponse \ "RequestID").text, + (xmlResponse \ "HostID").text) + + def this(response: String) = + this( + Try(XML.loadString(response)).getOrElse( + -{response}-- + ) + ) + + override def toString: String = + s"${super.toString} (Code: $code, RequestID: $requestId, HostID: $hostId)" + +}