Effect CommunityEC
Effect Community14mo ago
3 replies
Oung Seik

Handling ConfigError in Effect Layer with SqliteDbLive

In this case, I provide the SqliteDbLive to the Effect. But the SqliteDbLive might throw ConfigError.
export const EngineerApiLive: Layer.Layer<HttpApiGroup.ApiGroup<"engineers">> =
  HttpApiBuilder.group(EngineerApi, "engineers", (handlers) =>
    Effect.gen(function* () {
      const db = yield* SqliteDrizzle;

      return handlers.handle("register engineers", ({ payload }) => {
        db.insert(engineers).values({ ...payload });
        return Effect.succeed({ email: payload.email });
      });
    }).pipe(Effect.provide(SqliteDbLive)),
  );

So I got this error.
src/routers/Engineers.ts|43 col 14-29 error| Type 'Layer<ApiGroup<"engineers">, ConfigError, never>' is not assignable to type 'Layer<ApiGroup<"engineers">, never, never>'. Type 'ConfigError' is not assignable to type 'never'. Type 'And' is not assignable to type 'never'.

I would like to return HTTP 500 on Config Error case. How can I handle like that?
If that is not the best way to do, how can I improve the code?
Was this page helpful?