From 5cddece74e41944fe6a348222adf60d13f3173e0 Mon Sep 17 00:00:00 2001 From: garyaghedo Date: Thu, 5 Sep 2024 22:07:22 +0100 Subject: [PATCH] make the RawErrorResponse case class more binary compatibility-friendly --- .../core/src/smithy4s/http/HttpResponse.scala | 2 +- .../src/smithy4s/http/RawErrorResponse.scala | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/core/src/smithy4s/http/HttpResponse.scala b/modules/core/src/smithy4s/http/HttpResponse.scala index 770eb9425..ad20536aa 100644 --- a/modules/core/src/smithy4s/http/HttpResponse.scala +++ b/modules/core/src/smithy4s/http/HttpResponse.scala @@ -261,7 +261,7 @@ object HttpResponse { code = response.statusCode, headers = response.headers, body = bodyBlob.toUTF8String, - failedDecodeAttempt = + failedDecodeAttemptField = FailedDecodeAttempt.UnrecognisedDiscriminator( discriminator ) diff --git a/modules/core/src/smithy4s/http/RawErrorResponse.scala b/modules/core/src/smithy4s/http/RawErrorResponse.scala index 0c7eafbc5..7ed32a041 100644 --- a/modules/core/src/smithy4s/http/RawErrorResponse.scala +++ b/modules/core/src/smithy4s/http/RawErrorResponse.scala @@ -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 @@ -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(