Effect CommunityEC
Effect Community2d ago
7 replies
branperr

Handling Specific Error Codes in Effect Typescript Library

For sending back specific error codes, is it as simple as adding the error to the api schema and having the effect return that on the error channel, like this:

export const ApiRouter = HttpApi.make("My Api")
   .add(MyRoute)
   .addError(NotFound, {status:404})

// ... group schema

export const Route = HttpApiBuilder.group(ApiRouter, "myroute", handlers => handlers.handle("myroute", ()=> Effect.fail(new NotFound()))


I'm trying something like this, but I'm getting a 500 response instead
[09:28:58.867] INFO (#71) http.span.6=1ms:
  Error: {"_tag":"NotFound"}
      at http.server GET
  http.status: 500
  http.method: GET
  http.url: /image/blah
Was this page helpful?