Skip to content

Customizing HttpApiDecodeError responses #5465

Closed as not planned
Closed as not planned

Description

@Avaq

What is the problem this feature would solve?

I have an existing API that I want to create API specs for using the HttpApi module, before gradually implementing it using the HttpApiBuilder, phasing out its old implementation.

The API specs can be fully customised in what each endpoint responds with by using addSuccess and addError, except for one thing: The HttpApiDecodeError.

This means I'm unable to create an API spec to fully cover my existing API.

I posted this on Discord a while ago, but never got a response.

What is the feature you are proposing to solve the problem?

A setDecodeError method that takes a Schema<HttpApiDecodeError, T> so I can customize how those are encoded:

const HttpApiDecodeErrorFromMyWeirdValidationError =
  Schema.transform(
    MyWeirdValidationError,
    HttpApiDecodeError.HttpApiDecodeError,
    { encode: (yours) => ({...}), decode: (mine) => ({...}) }
  )
  
export default HttpApi.make('myApi')
.add(MyApiGroup)
.setDecodeError(HttpApiDecodeErrorFromMyWeirdValidationError) // <--- override
.addError(MyWeirdInternalServerError, { status: 500 })

What alternatives have you considered?

Hacking the response with a middleware, and hacking the OpenAPI JSON object: #5367 (comment)

Activity

  1. added
    enhancement
    on Sep 4, 2025
  2. Avaq commented on Oct 2, 2025

    @Avaq
    ContributorAuthor

    Reposting @gcanti's proposal here for visibility:

    What about a replaceError(f: (prev: Schema | undefined) => Schema | undefined) API instead of addError? This would let the user decide what comes first, while system-added schemas would always be placed at the end.

    -- #5479 (comment)

  3. added
    3.0
    on Jul 14, 2026
  4. tim-smart commented on Jul 28, 2026

    @tim-smart
    Contributor

    Automated message: Effect v3 is now under a feature freeze and is now only considering bug fixes.

    If this issue is still relevant for v4, then feel free to reopen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions