Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errorFormatter returns invalid openapi schema #205

Open
matannahmani opened this issue Dec 18, 2022 · 5 comments
Open

errorFormatter returns invalid openapi schema #205

matannahmani opened this issue Dec 18, 2022 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@matannahmani
Copy link

matannahmani commented Dec 18, 2022

I've been using errorFormatter to include Zod errors and more custom errors, but the returned
error type in openapi schema doesn't synchronize
trpc error formatter:

    errorFormatter({ shape, error }) {
        return {
            ...shape,
            data: {
                ...shape.data,
                errCode: error.cause instanceof CustomTRPCError ? error.cause.errCode : null,
                zodError:
                    error.code === 'BAD_REQUEST' &&
                        error.cause instanceof ZodError
                        ? error.cause.flatten()
                        : null,
            },
        };
    }

return open-api schema:

{
  "message": "string",
  "code": "string",
  "issues": [
    {
      "message": "string"
    }
  ]
}

real response:

{
  "message": "Input validation failed",
  "code": "BAD_REQUEST",
  "issues": [
    {
      "validation": "uuid",
      "code": "invalid_string",
      "message": "Invalid uuid",
      "path": [
        "keyRingKeyId"
      ]
    }
  ]
}
@matannahmani
Copy link
Author

I would suggest adding an option to override errorResponseObject with your own error object

@jlalmes jlalmes added the enhancement New feature or request label Dec 30, 2022
@stale
Copy link

stale bot commented Feb 28, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 28, 2023
@stale stale bot closed this as completed Mar 8, 2023
@jlalmes jlalmes added help wanted Extra attention is needed and removed stale labels May 24, 2023
@jlalmes jlalmes reopened this May 24, 2023
@aagwali
Copy link

aagwali commented Jul 24, 2023

Hello,

Any news on this topic ?

I'm having a use case where I try to add some data to a 409 error (the conflicting object).
I cannot find a way to return anything attached to the error.

@cgyrock
Copy link

cgyrock commented Dec 8, 2023

image
unfortunately,they hard code the condition,while zodError occur,force set message as ‘Input validation failed’

image
we can just change “error.caus.name” to break the condition.

I had tried it works!

@aagwali

@ulyr
Copy link

ulyr commented Feb 21, 2024

is there even a reason to limit the shape of the response body? I think that's the purpose of the trpc errorFormatter that we're all using, I think trpc-openapi should just take the error object as it is and pass it on...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants