Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add more detail to exceptions thrown in the client interpreter" #4094

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading