Is there a way to add a default error mapper for my HttpApi?
Hello! This is my first time using the HttpApi module with Effect.
This is my current implementation:
This is how my PrismaError looks like:
Is there a way I can avoid having to add the catchTag to all of my handlers? I dont really want to expose te PrismaError through my api contract.
This is my current implementation:
import { HttpApiBuilder, HttpApiError } from "@effect/platform";
import { Effect } from "effect";
import { CashApi } from "../contracts/api";
import { RakeModelService } from "../services/rake-model";
HttpApiBuilder.group(CashApi, "CashRakeModel", (handlers) =>
Effect.gen(function* () {
const rakeModelService = yield* RakeModelService;
return handlers
.handle("createRakeModel", ({ payload }) =>
rakeModelService
.createRakeModel(payload)
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
)
.handle("getRakeModels", () =>
rakeModelService
.getRakeModels()
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
)
.handle("getRakeModel", ({ path }) =>
rakeModelService
.getRakeModel(path.id)
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
);
})
);import { HttpApiBuilder, HttpApiError } from "@effect/platform";
import { Effect } from "effect";
import { CashApi } from "../contracts/api";
import { RakeModelService } from "../services/rake-model";
HttpApiBuilder.group(CashApi, "CashRakeModel", (handlers) =>
Effect.gen(function* () {
const rakeModelService = yield* RakeModelService;
return handlers
.handle("createRakeModel", ({ payload }) =>
rakeModelService
.createRakeModel(payload)
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
)
.handle("getRakeModels", () =>
rakeModelService
.getRakeModels()
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
)
.handle("getRakeModel", ({ path }) =>
rakeModelService
.getRakeModel(path.id)
.pipe(
Effect.catchTag(
"PrismaError",
() => new HttpApiError.InternalServerError()
)
)
);
})
);This is how my PrismaError looks like:
export class PrismaError extends Data.TaggedError("PrismaError")<{
details: SomePrismaError;
}> {}export class PrismaError extends Data.TaggedError("PrismaError")<{
details: SomePrismaError;
}> {}Is there a way I can avoid having to add the catchTag to all of my handlers? I dont really want to expose te PrismaError through my api contract.
