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

don't crash ws connection when there's an internal error #245

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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 @@ -155,7 +155,7 @@ object Connection {
case Success(op) => if (service.isSubscription(op)) subscribe(id, op) else execute(id, op)
case Warning(_, op) => if (service.isSubscription(op)) subscribe(id, op) else execute(id, op) // n.b. warnings on subscribe are lost
case Failure(ps) => send(Error(id, ps.toNonEmptyList.map(mkGraphqlError)).some)
case InternalError(err) => err.raiseError[F, Unit]
case InternalError(err) => send(Error(id, mkGraphqlErrors(err)).some)
}
(this, action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ package object routes {
def mkGraphqlErrors(problems: NonEmptyChain[Problem]): GraphQLErrors =
problems.toNonEmptyList.map(mkGraphqlError)

def mkGraphqlErrors(error: Throwable): GraphQLErrors =
NonEmptyList.one(mkGraphqlError(Problem(s"Internal Error: ${error.getMessage}")))

def mkFromServer[F[_]: MonadThrow](r: Result[Json], id: String): F[Either[FromServer.Error, FromServer.Data]] =
r match {
case Success(json) => FromServer.Data(id, GraphQLResponse(json.rightIor)).asRight.pure[F]
case Warning(ps, json) => FromServer.Data(id, GraphQLResponse(Ior.both(mkGraphqlErrors(ps), json))).asRight.pure[F]
case Failure(ps) => FromServer.Error(id, mkGraphqlErrors(ps)).asLeft.pure[F]
case InternalError(err) => MonadThrow[F].raiseError(err)
case InternalError(err) => FromServer.Error(id, mkGraphqlErrors(err)).asLeft.pure[F]
}

}
Loading