Skip to content

Commit

Permalink
issue-1438: make all field private
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryAghedo committed Sep 11, 2024
1 parent 5cddece commit d9b64e8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 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,
failedDecodeAttemptField =
failedDecodeAttempt =
FailedDecodeAttempt.UnrecognisedDiscriminator(
discriminator
)
Expand Down
56 changes: 53 additions & 3 deletions modules/core/src/smithy4s/http/RawErrorResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,53 @@
package smithy4s.http

case class RawErrorResponse(
code: Int,
headers: Map[CaseInsensitive, Seq[String]],
body: String,
private val codeField: Int,
private val headersField: Map[CaseInsensitive, Seq[String]],
private val bodyField: String,
private val failedDecodeAttemptField: FailedDecodeAttempt
) extends Throwable {

def code: Int = codeField
def headers: Map[CaseInsensitive, Seq[String]] = headersField
def body: String = bodyField
def failedDecodeAttempt: FailedDecodeAttempt = failedDecodeAttemptField

def withCode(newCode: Int): RawErrorResponse =
new RawErrorResponse(
newCode,
headersField,
bodyField,
failedDecodeAttemptField
)

def withHeaders(
newHeaders: Map[CaseInsensitive, Seq[String]]
): RawErrorResponse =
new RawErrorResponse(
codeField,
newHeaders,
bodyField,
failedDecodeAttemptField
)

def withBody(newBody: String): RawErrorResponse =
new RawErrorResponse(
codeField,
headersField,
newBody,
failedDecodeAttemptField
)

def withFailedDecodeAttempt(
newFailedDecodeAttempt: FailedDecodeAttempt
): RawErrorResponse =
new RawErrorResponse(
codeField,
headersField,
bodyField,
newFailedDecodeAttempt
)

override def getMessage(): String = {
val baseMessage = s"status $code, headers: $headers, body:\n$body"
baseMessage + s"""
Expand All @@ -36,6 +75,17 @@ case class RawErrorResponse(
override def getCause: Throwable = failedDecodeAttempt
}

object RawErrorResponse {
def apply(
code: Int,
headers: Map[CaseInsensitive, Seq[String]],
body: String,
failedDecodeAttempt: FailedDecodeAttempt
): RawErrorResponse =
new RawErrorResponse(code, headers, body, failedDecodeAttempt)

}

sealed trait FailedDecodeAttempt extends Throwable {
def discriminator: HttpDiscriminator
def getMessage: String
Expand Down

0 comments on commit d9b64e8

Please sign in to comment.