Effect CommunityEC
Effect Community6mo ago
4 replies
Aldwin

Customizing HttpApiDecodeError responses

Hi! I have an existing API that I want to create API specs for using the HttpApi module. This should allow me to (optionally) crate an alternative implementation using the HttpApiBuilder, but also immediately use it to generate a client, docs, etc.

The existing API sends request validation errors with status code 400, in the shape:
{
  success: false,
  error: { type: "ValidationError", issues: Issue[] }
}


But any API spec created with HttpApi is going to add the following as one of possible errors by default:
{
  _tag: "HttpApiDecodeError",
  message: string,
  issues: Issue[]
}


Since it's technically feasible to map Effect's HttpApiDecodeError to my own ValidationError, is it possible to provide this mapping to the HttpApi specs, so that:

1. My generated API docs include only the transformed error type; and
2. A possible implementation of the spec using HttpApiBuilder automatically uses this mapper to transform the HttpApiDecodeError into my custom ValidationError before it sends the response?


- Related to: help-forumServer / API level defect handling
- Related to: platform
Was this page helpful?