Effect CommunityEC
Effect Community3y ago
6 replies
attila

Returning a Response from Middleware to Short Circuit Middleware Chain

How do I correctly return a response from a middleware and short circuit the chain of middlewares?

const shortCircuit = Http.middleware.make((_httpApp) =>
  Effect.succeed(Http.response.empty({ status: 401 }))
);


The above does not work. Requests just keep hanging. If I return the _httpApp, it successfully passes the control down to the next middleware. As far as I understand, a Middleware is just a function that takes an App.Default and returns an App.Default. And an App.Default is just an Effect that succeeds with a ServerResponse: Effect.Effect<R | ServerRequest.ServerRequest, E, ServerResponse>.

I'm failing to see why Effect.succeed(Http.response.empty({ status: 401 })) would not be a correct App.Default. The compiler is happy, it just doesn't work at runtime.
Was this page helpful?