smithy4s icon indicating copy to clipboard operation
smithy4s copied to clipboard

Issue-1438: Fix upstream service error represented as 400

Open GaryAghedo opened this issue 1 year ago • 3 comments

Issue -https://github.com/disneystreaming/smithy4s/issues/1438

Issue description: When an upstream service fails with a non-parseable response (e.g., due to an internal server error), the Smithy4s client wraps this failure in an HttpPayloadError. Currently, the Smithy4s server interprets this HttpPayloadError as a client-side error and responds with a 400 BadRequest. This behaviour incorrectly suggests that the error originated from the client's request, making it difficult to debug actual upstream service failures. The correct behaviour should be for the server to respond with a 500 InternalServerError, indicating an issue with the upstream service rather than the client's request.

Solution:

Define a new error type RawErrorResponse:

Created a new error type RawErrorResponse to represent detailed errors, including a failed decode attempt, originating from upstream services. Update HttpResponse:

Updated HttpResponse to handle RawErrorResponse by including detailed information about the failed decode attempt when appropriate.

Test Added a test case to PizzaSpec to validate the server's response when a RawErrorResponse is raised, ensuring that it returns a 500 status code with detailed information about the failed decode attempt.

  • [x] Added unit-tests (for runtime code)
  • [ ] Added bootstrapped code + smoke tests (when the rendering logic is modified)
  • [ ] Added build-plugins integration tests (when reflection loading is required at codegen-time)
  • [ ] Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)
  • [ ] Updated dynamic module to match generated-code behaviour
  • [ ] Added documentation
  • [ ] Updated changelog

GaryAghedo avatar Jul 24 '24 16:07 GaryAghedo

@GaryAghedo for these errors:

There are files without headers!

You should be able to generate the missing headers with sbt headerCreateAll.

kubukoz avatar Aug 06 '24 13:08 kubukoz

Hey @Baccata. PR ready to be reviewed thanks

GaryAghedo avatar Aug 09 '24 04:08 GaryAghedo

I think it's shaping up well, but there's still a couple things to take care of though. Good work though !

Baccata avatar Aug 19 '24 13:08 Baccata