diff --git a/interop/tapir/src/main/scala/caliban/interop/tapir/ws/Protocol.scala b/interop/tapir/src/main/scala/caliban/interop/tapir/ws/Protocol.scala index 506a242f13..48b00d55cd 100644 --- a/interop/tapir/src/main/scala/caliban/interop/tapir/ws/Protocol.scala +++ b/interop/tapir/src/main/scala/caliban/interop/tapir/ws/Protocol.scala @@ -86,7 +86,7 @@ object Protocol { afterInit .catchAllCause(cause => ZIO.foreachDiscard(cause.failureOption)(e => - generateId(id).map(uuid => output.offer(Right(handler.error(uuid, e)))) + generateId(id).flatMap(uuid => output.offer(Right(handler.error(uuid, e)))) ) *> output.offer(Left(GraphQLWSClose(4401, "Unauthorized"))) ) .fork @@ -96,7 +96,7 @@ object Protocol { case GraphQLWSInput(Ops.Pong, id, payload) => ZIO.whenCase(webSocketHooks.onPong -> payload) { case (Some(onPong), Some(payload)) => onPong(payload).catchAll(e => - generateId(id).map(uuid => output.offer(Right(handler.error(uuid, e)))) + generateId(id).flatMap(uuid => output.offer(Right(handler.error(uuid, e)))) ) } case GraphQLWSInput(Ops.Ping, id, payload) => @@ -106,7 +106,9 @@ object Protocol { case Some(onPing) => onPing(payload) .flatMap(sendPong) - .catchAll(e => generateId(id).map(uuid => output.offer(Right(handler.error(uuid, e))))) + .catchAll(e => + generateId(id).flatMap(uuid => output.offer(Right(handler.error(uuid, e)))) + ) case _ => sendPong(None) } case GraphQLWSInput(Ops.Subscribe, Some(id), payload) => @@ -136,7 +138,7 @@ object Protocol { ) case None => - generateId(None).map(uuid => output.offer(Right(connectionError(uuid)))) + generateId(None).flatMap(uuid => output.offer(Right(connectionError(uuid)))) } ZIO.ifZIO(ack.get)(continue, output.offer(Left(GraphQLWSClose(4401, "Unauthorized")))) @@ -146,7 +148,7 @@ object Protocol { output.offer(Left(GraphQLWSClose(4400, s"Unsupported operation: $unsupported"))) }.runDrain.interruptible .catchAll(_ => - generateId(None).map(uuid => output.offer(Right(connectionError(Some(uuid.toString()))))) + generateId(None).flatMap(uuid => output.offer(Right(connectionError(Some(uuid.toString()))))) ) .ensuring(subscriptions.untrackAll) .provideEnvironment(env)