Skip to content

Commit

Permalink
Merge branch 'master' into fix-enum-pickler
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw authored Oct 9, 2024
2 parents 31b4e7c + 9f765c8 commit 52ea6fe
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ trait SttpClientInterpreter extends SttpClientInterpreterExtensions {
def toRequestThrowErrors[I, E, O, R](e: PublicEndpoint[I, E, O, R], baseUri: Option[Uri])(implicit
wsToPipe: WebSocketToPipe[R]
): I => Request[O, R] =
i => {
val request = new EndpointToSttpClient(sttpClientOptions, wsToPipe).toSttpRequest(e, baseUri).apply(()).apply(i)
request
i =>
new EndpointToSttpClient(sttpClientOptions, wsToPipe)
.toSttpRequest(e, baseUri)
.apply(())
.apply(i)
.mapResponse(throwDecodeFailures)
.mapResponse {
case Left(t: Throwable) => throw new RuntimeException(throwErrorExceptionMsg(e, i, t.asInstanceOf[E], request), t)
case Left(t) => throw new RuntimeException(throwErrorExceptionMsg(e, i, t, request))
case Left(t: Throwable) => throw new RuntimeException(throwErrorExceptionMsg(e, i, t.asInstanceOf[E]), t)
case Left(t) => throw new RuntimeException(throwErrorExceptionMsg(e, i, t))
case Right(o) => o
}
}

// secure

Expand Down Expand Up @@ -191,16 +192,17 @@ trait SttpClientInterpreter extends SttpClientInterpreterExtensions {
wsToPipe: WebSocketToPipe[R]
): A => I => Request[O, R] =
a =>
i => {
val request = new EndpointToSttpClient(sttpClientOptions, wsToPipe).toSttpRequest(e, baseUri).apply(a).apply(i)
request
i =>
new EndpointToSttpClient(sttpClientOptions, wsToPipe)
.toSttpRequest(e, baseUri)
.apply(a)
.apply(i)
.mapResponse(throwDecodeFailures)
.mapResponse {
case Left(t: Throwable) => throw new RuntimeException(throwErrorExceptionMsg(e, a, i, t.asInstanceOf[E], request), t)
case Left(t) => throw new RuntimeException(throwErrorExceptionMsg(e, a, i, t, request))
case Left(t: Throwable) => throw new RuntimeException(throwErrorExceptionMsg(e, a, i, t.asInstanceOf[E]), t)
case Left(t) => throw new RuntimeException(throwErrorExceptionMsg(e, a, i, t))
case Right(o) => o
}
}

//

Expand All @@ -211,11 +213,11 @@ trait SttpClientInterpreter extends SttpClientInterpreterExtensions {
case f => throw new IllegalArgumentException(s"Cannot decode: $f")
}

private def throwErrorExceptionMsg[I, E, O, R](endpoint: PublicEndpoint[I, E, O, R], i: I, e: E, r: Request[_, _]): String =
s"Endpoint ${endpoint.show} returned error: $e, inputs: $i. Request: ${r.showBasic}."
private def throwErrorExceptionMsg[I, E, O, R](endpoint: PublicEndpoint[I, E, O, R], i: I, e: E): String =
s"Endpoint ${endpoint.show} returned error: $e, inputs: $i."

private def throwErrorExceptionMsg[A, I, E, O, R](endpoint: Endpoint[A, I, E, O, R], a: A, i: I, e: E, r: Request[_, _]): String =
s"Endpoint ${endpoint.show} returned error: $e, for security inputs: $a, inputs: $i. Request: ${r.showBasic}."
private def throwErrorExceptionMsg[A, I, E, O, R](endpoint: Endpoint[A, I, E, O, R], a: A, i: I, e: E): String =
s"Endpoint ${endpoint.show} returned error: $e, for security inputs: $a, inputs: $i."
}

object SttpClientInterpreter {
Expand Down

0 comments on commit 52ea6fe

Please sign in to comment.