Skip to content

Commit

Permalink
make the RawErrorResponse case class more binary compatibility-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryAghedo committed Sep 5, 2024
1 parent 66dc50a commit 5cddece
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/core/src/smithy4s/http/HttpResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ object HttpResponse {
code = response.statusCode,
headers = response.headers,
body = bodyBlob.toUTF8String,
failedDecodeAttempt =
failedDecodeAttemptField =
FailedDecodeAttempt.UnrecognisedDiscriminator(
discriminator
)
Expand Down
17 changes: 10 additions & 7 deletions modules/core/src/smithy4s/http/RawErrorResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ case class RawErrorResponse(
code: Int,
headers: Map[CaseInsensitive, Seq[String]],
body: String,
failedDecodeAttempt: FailedDecodeAttempt
private val failedDecodeAttemptField: FailedDecodeAttempt
) extends Throwable {

def failedDecodeAttempt: FailedDecodeAttempt = failedDecodeAttemptField

override def getMessage(): String = {
val baseMessage = s"status $code, headers: $headers, body:\n$body"
baseMessage +
s"""
|FailedDecodeAttempt:
| ${failedDecodeAttempt.getMessage}
""".stripMargin
baseMessage + s"""
|FailedDecodeAttempt:
| ${failedDecodeAttempt.getMessage}
""".stripMargin
}

override def getCause: Throwable = failedDecodeAttempt
Expand All @@ -40,10 +42,11 @@ sealed trait FailedDecodeAttempt extends Throwable {
}

object FailedDecodeAttempt {

case class UnrecognisedDiscriminator(discriminator: HttpDiscriminator)
extends FailedDecodeAttempt {
override def getMessage: String =
s"Unrecognised descriminator: $discriminator"
s"Unrecognised discriminator: $discriminator"
}

case class DecodingFailure(
Expand Down

0 comments on commit 5cddece

Please sign in to comment.