-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
From Discord: Unexpected Behavior in HTTP Middleware: Unhandled Errors Cause Request Hang #3391
Comments
recreation import { HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform";
import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
import { Console, Effect, Layer } from "effect";
const Server = HttpRouter.empty.pipe(
HttpRouter.all("*", HttpServerResponse.empty()),
HttpRouter.use(() => Effect.fail("BOOM!")), // fine
HttpServer.serve(() => Effect.fail("KAPAW!")), // drops the request
Layer.provide(BunHttpServer.layer({ port: 3000 })),
);
Layer.launch(Server).pipe(
Effect.catchAllCause(Console.error),
BunRuntime.runMain,
); The key takeaways for real are
|
playground by user (not sure it"s useful since it"s a server) |
Possibly related, but I get server hangs from the following as well: import {
HttpApp,
HttpMiddleware,
HttpRouter,
HttpServerResponse,
} from "@effect/platform";
import { Effect, flow, pipe } from "effect";
export async function brokenFetchHandler(request: Request): Promise<Response> {
console.log("enter broken fetch handler", { request });
const myBrokenMiddleware = <E, R>(
httpApp: HttpApp.Default<E, R>,
): HttpApp.Default<E, R> =>
Effect.succeed(HttpServerResponse.empty({ status: 208 }));
return pipe(
request,
HttpApp.toWebHandler(
HttpRouter.empty,
flow(myBrokenMiddleware, HttpMiddleware.logger),
),
);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
The conversation revolves around an issue with HTTP middleware in the Effect-TS ecosystem, where unhandled errors cause the request to hang without any compiler warnings or default server responses. The user provided a reproducible example, and another user, datner_, identified the problem in the
HttpApp.toHandled
function, specifically in how it handles middleware failures. Datner_ suggested moving the middleware toHttpRouter.use
instead ofHttpServer.serve
as a workaround. Key takeaways include:HttpRouter.use
.HttpApp.toHandled
function"s error handling logic.Discord thread
https://discord.com/channels/795981131316985866/1268169538047049729
The text was updated successfully, but these errors were encountered: