Skip to content

Allow HttpApiEndpoint to override HttpApiDecodeError response #4751

Closed

Description

@dmeehan1968

What version of Effect is running?

3.14.5

What steps can reproduce the bug?

Create an endpoint and set success and error. In this case, I just want 400 Bad Request to be the empty response, not the HttpApiDecodeError. I don't see a method that allows me to remove the default error response, so defining my own just adds to the HttpApiDecodeError response (as is consistent with adding multiple error types).

As an aside, given that this endpoint doesn't defined a request payload or path/query params, it seems odd that the api should define a decode error response at all.

const api = HttpApi.make('api')
  .add(HttpApiGroup.make('devices')
    .add(HttpApiEndpoint.get('listDevices')`/devices`
      .addSuccess(DeviceListSchema)
      .addError(HttpApiError.BadRequest)
      .addError(HttpApiError.Unauthorized)
      .addError(HttpApiError.InternalServerError)
    )
  )
paths:
  /devices:
    get:
      tags:
        - devices
      operationId: devices.listDevices
      parameters: []
      security: []
      responses:
        '200':
          description: A list of Device entities with pagination information
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeviceList'
        '400':
          description: The request did not match the expected schema
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HttpApiDecodeError'
                  - $ref: '#/components/schemas/BadRequest'
        '401':
          description: Unauthorized
        '500':
          description: InternalServerError

Note that in the yaml (generated by using OpenApi.fromApi and the converting to YAML) under the 400 response, it now shows a union of response schema. HttpApiDecodeError does not match the desired response format for this type of error, and in the implementation I would want to catch this error and produce my own (empty in this example, but could be another response schema that suits my application).

In my case, I am going to use the OpenApi spec to generate AWS Api Gateway infrastructure, and so I don't need an Effect implementation, as I will inject the necessary AWS extensions into the OpenApi spec to add my Lambda handlers. I will intend to publish the OpenApi spec as output by @effect/platform as a way of documenting the API for consumers.

What is the expected behavior?

        '400':
          description: The request did not match the expected schema
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/BadRequest'

What do you see instead?

        '400':
          description: The request did not match the expected schema
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HttpApiDecodeError'
                  - $ref: '#/components/schemas/BadRequest'

Additional information

No response

Activity

  1. added
    bug
    on Apr 16, 2025
  2. janstuemmel commented on Sep 16, 2025

    @janstuemmel

    +1 i think this issue is really important. without we cant simply build a rest api

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

    @tim-smart
    Contributor

    This has been addressed in v4

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.0bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions