Skip to content

Commit

Permalink
Try to restore bincompat
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostbuster91 committed Aug 16, 2024
1 parent efe996b commit 023d9e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
28 changes: 18 additions & 10 deletions modules/core/src/smithy4s/http/HttpErrorSelector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ object HttpErrorSelector {
def apply[F[_]: Covariant, E](
maybeErrorSchema: Option[ErrorSchema[E]],
compiler: CachedSchemaCompiler[F]
): HttpDiscriminator => Option[F[E]] =
makeWithReason(maybeErrorSchema, compiler).andThen(_.toOption)

def makeWithReason[F[_]: Covariant, E](
maybeErrorSchema: Option[ErrorSchema[E]],
compiler: CachedSchemaCompiler[F]
): HttpDiscriminator => Either[String, F[E]] = maybeErrorSchema match {
case None => _ => Left("error schema not found")
case Some(errorschema) =>
Expand All @@ -61,19 +67,21 @@ object HttpErrorSelector {
def asThrowable[F[_]: Covariant, E](
maybeErrorSchema: Option[ErrorSchema[E]],
compiler: CachedSchemaCompiler[F]
): HttpDiscriminator => Option[F[Throwable]] = asThrowableWithError(maybeErrorSchema, compiler).andThen(_.toOption)
): HttpDiscriminator => Option[F[Throwable]] =
asThrowableWithReason(maybeErrorSchema, compiler).andThen(_.toOption)

def asThrowableWithError[F[_]: Covariant, E](
def asThrowableWithReason[F[_]: Covariant, E](
maybeErrorSchema: Option[ErrorSchema[E]],
compiler: CachedSchemaCompiler[F]
): HttpDiscriminator => Either[String, F[Throwable]] = maybeErrorSchema match {
case None => _ => Left("error schema not found")
case Some(errorschema) =>
new HttpErrorSelector[F, E](
errorschema.alternatives,
compiler
).andThen(_.map(Covariant[F].map(_)(errorschema.unliftError)))
}
): HttpDiscriminator => Either[String, F[Throwable]] =
maybeErrorSchema match {
case None => _ => Left("error schema not found")
case Some(errorschema) =>
new HttpErrorSelector[F, E](
errorschema.alternatives,
compiler
).andThen(_.map(Covariant[F].map(_)(errorschema.unliftError)))
}

}

Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/smithy4s/http/HttpResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ object HttpResponse {
): Decoder[F, Body, Throwable] =
discriminating(
discriminate,
HttpErrorSelector.asThrowableWithError(maybeErrorSchema, decoderCompiler),
HttpErrorSelector
.asThrowableWithReason(maybeErrorSchema, decoderCompiler),
toStrict
)

Expand Down

0 comments on commit 023d9e3

Please sign in to comment.