Effect CommunityEC
Effect Community2mo ago
14 replies
mechanical_monk

Custom Validation Error Shape with HttpApi in Effect Typescript

with HttpApi, how can I define a custom shape for validation errors?
const flagId = HttpApiSchema.param("id", Schema.UUID);
const createFlagEndpoint = HttpApiEndpoint.post("create-flag")`/`
    .setPayload(FlagPayload)
    .addSuccess(Flag, { status: 201 });
const getFlagEndpoint = HttpApiEndpoint.get("get-flag")`/${flagId}`
    .addSuccess(Flag)
    .addError(FlagNotFound);

on DecodeError in either payload or params, I'd like to send back a custom JSON error response, using the message from the DecodeError.
I couldn't find anything about it in the effect/platform documentation on Github.
Was this page helpful?