Issues with Effect in HttpServerResponse and Error Handling in Router Signature
Hi, I am trying the most basic example, trying to figure out how this works. I I put an effect inside the
HttpServerResponse.json()
HttpServerResponse.json()
and I get the effect in the response not the json object.
Also if I create an effect that alwais fail with a custom error message I do not see this error message in the router signature.
// main.tsimport { HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform";import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";import { Layer } from "effect";import { createServer } from "node:http";import { getBird } from "./bird.ts";// Define the router with a single route for the root URLconst router = HttpRouter.empty.pipe( HttpRouter.get("/hellow", HttpServerResponse.text("Hello World")), HttpRouter.get("/", HttpServerResponse.json(getBird)),);// Set up the application server with loggingconst app = router.pipe(HttpServer.serve(), HttpServer.withLogAddress);// Specify the portconst port = 3000;// Create a server layer with the specified portconst ServerLive = NodeHttpServer.layer(() => createServer(), { port });// Run the applicationNodeRuntime.runMain(Layer.launch(Layer.provide(app, ServerLive)));// bird.tsimport { Data, Effect } from "effect";class HttpMyError extends Data.TaggedError("HttpError")<{}> {}// ┌─── Effect<never, HttpError, never>// ▼// export const getBird = Effect.fail(new HttpMyError());export const getBird = Effect.succeed({ a: "2", b: "23" });
// main.tsimport { HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform";import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";import { Layer } from "effect";import { createServer } from "node:http";import { getBird } from "./bird.ts";// Define the router with a single route for the root URLconst router = HttpRouter.empty.pipe( HttpRouter.get("/hellow", HttpServerResponse.text("Hello World")), HttpRouter.get("/", HttpServerResponse.json(getBird)),);// Set up the application server with loggingconst app = router.pipe(HttpServer.serve(), HttpServer.withLogAddress);// Specify the portconst port = 3000;// Create a server layer with the specified portconst ServerLive = NodeHttpServer.layer(() => createServer(), { port });// Run the applicationNodeRuntime.runMain(Layer.launch(Layer.provide(app, ServerLive)));// bird.tsimport { Data, Effect } from "effect";class HttpMyError extends Data.TaggedError("HttpError")<{}> {}// ┌─── Effect<never, HttpError, never>// ▼// export const getBird = Effect.fail(new HttpMyError());export const getBird = Effect.succeed({ a: "2", b: "23" });