-
Notifications
You must be signed in to change notification settings - Fork 603
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
feat: support multiple error headers #3852
Conversation
This change takes the first header value from x-amzn-errortype if multiple headers are provided. An example curl output for a response that this works for: ``` HTTP/2 401 date: Tue, 09 Aug 2022 21:24:20 GMT content-type: application/json content-length: 92 x-amzn-requestid: xxxx access-control-allow-origin: * x-amzn-errortype: UnauthorizedError x-amzn-errortype: UnauthorizedException x-amz-apigw-id: xxxx x-amzn-trace-id: Root=xxxx ``` In this instance this code will select the first header value. See related - smithy-lang/smithy#1170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- run codegen for clients
I can do that and merge when able
Hey @kuhe, did you request changes with this comment? Trying to understand if I'm missing something in the ui. |
merging to run codegen on my own branch. I think the build errors are due to smithy being out of date on this branch, and will override. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Issue
smithy-lang/smithy#1170
Description
This change adds support for multiple values in the x-amzn-errortype header. The reason for this is that API-Gateway always adds its own x-amzn-errortype header on gateway responses. This header that APIG adds and does not let the customer configure will almost never match the specific errors that customers model for their API. As an aside, I have logged a feature request for APIG to support configuration of this header - however this is unlikely to be delivered any time soon.
Anyone using this package today to generate clients of their own therefore cannot use gateway responses and have a functioning SDK for their errors. It isn't possible to avoid gateway responses for things like auth/throttling when those are configured on the apig.
This change takes the first header value from x-amzn-errortype if multiple headers are provided. It has no effect when a single header is provided.
An example curl output for a response that this works for:
In this instance this code will select the first header value.
Testing
I built and inspected the codegen/generic-client-test/build/smithyprojections/generic-client-test/echo-service/typescript-codegen/src/protocols/Aws_restJson1.ts file.
Contents is as expected:
I didn't find tests exercising this client in the repository.
Additional context
There are a few other things that can be considered here
Do we need to support commas in header values, data.code or data["__type"]
I suspect not. A comma isn't valid in a fully qualified structure name for smithy/openapi.
There's code to split on a ":". I don't know what that is for and if we'd ever expect commas before that colon.
Alternatives
I've considered a few alternatives which I'll enumerate below and would be happy to implement.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.