Skip to content

Commit

Permalink
copy old S3Exception code from Alpakka
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed May 27, 2024
1 parent 7ea18eb commit d0ac3e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://spray.io>

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. <http://www.lightbend.com>

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.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@
* limitations under the License.
*/

/*
* Copyright (C) 2016-2019 Lightbend Inc. <http://www.lightbend.com>
*/

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(
<Error><Code>-</Code><Message>{response}</Message><RequestID>-</RequestID><HostID>-</HostID></Error>
)
)

override def toString: String =
s"${super.toString} (Code: $code, RequestID: $requestId, HostID: $hostId)"

}

0 comments on commit d0ac3e2

Please sign in to comment.