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

Return 502 for gateway validation errors #2111

Merged
merged 7 commits into from
Dec 5, 2024
Merged

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Nov 8, 2024

Summary

When validating the response of a service, we return a 500. This is a vague response.

This changes server validation-related error codes to 502.

Changes

  • Change server validation-related errors codes

@iamacook iamacook self-assigned this Nov 8, 2024
@iamacook iamacook requested a review from a team as a code owner November 8, 2024 12:59
Copy link
Contributor

@PooyaRaki PooyaRaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why do we need to change the response status code to 502?

For validation errors, the appropriate status code is generally 400 Bad Request, as it indicates an issue with the request sent by the client. However, since this is an internal validation error (an issue occurring within our service logic rather than due to a client error), 500 Internal Server Error is more suitable. This code reflects that the error was caused by the server’s internal processing rather than by the client’s input.

Base automatically changed from caip-10-schema to main November 14, 2024 14:47
@hectorgomezv
Copy link
Member

This error happened because the way AppModule was initialized in list-queued-transactions-by-safe.transactions.controller.spec.ts prevented the injection of the Interceptors/Filters, and therefore the ZodError filter wasn't applied. I've created and merged a PR to fix this in #2127. After that, rebasing this onto main will make the tests pass 🙂

Question: Why do we need to change the response status code to 502?

For validation errors, the appropriate status code is generally 400 Bad Request, as it indicates an issue with the request sent by the client. However, since this is an internal validation error (an issue occurring within our service logic rather than due to a client error), 500 Internal Server Error is more suitable. This code reflects that the error was caused by the server’s internal processing rather than by the client’s input.

I don't have a strong opinion regarding this, but I think distinguishing 500/generic errors from 502 errors caused by server-side validation can be beneficial 🙂

@iamacook
Copy link
Member Author

iamacook commented Dec 4, 2024

Question: Why do we need to change the response status code to 502?

As per discussion: this allows us to distinguish datasource validation. Whilst we want to reassess/improve our error handling, this is a simple adjustment to distinguish the aforemented for the time being.

Note: this includes the changes of #2174 to save exposing a 500.

@iamacook iamacook requested a review from PooyaRaki December 4, 2024 16:19
@iamacook iamacook merged commit 22b5f65 into main Dec 5, 2024
21 checks passed
@iamacook iamacook deleted the bad-gateway-validation branch December 5, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants