Skip to content

Commit

Permalink
Return an effect from generateId
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenW committed Aug 25, 2023
1 parent 256ef5b commit fa8d11c
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) =>
Expand All @@ -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) =>
Expand Down Expand Up @@ -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"))))
Expand All @@ -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)
Expand Down

0 comments on commit fa8d11c

Please sign in to comment.