You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(auth): SyntaxError not being considered Network Error (aws#5512)
## Problem:
There were some previous changes that caused the existing implementation
of a `SyntaxError` to not be considered a Network Error. And during
token refresh we were seeing SyntaxErrors still appearing
## Solution:
Create a single class which wraps a `SyntaxError`, called
`AwsClientResponseError`. Under the hood of a SyntaxError is the real
error that originates from a failed AWS SDK Client response, this is how
we determine if it should be an `AwsClientResponseError`. This new class
can only be created if given the correct SyntaxError instance to
`AwsClientResponseError.instanceIf()`.
Then we can simply check if an error matches by using `instanceif
AwsClientResponseError`
Any existing code that was related to this scenario has all been
centralized in to the AwsClientResponseError class.
---
<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->
License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
---------
Signed-off-by: Nikolas Komonen <[email protected]>
* AWS SDK clients may rarely make requests that results in something other than JSON data
891
-
* being returned (e.g html). This will cause the client to throw a SyntaxError as a result
878
+
* AWS SDK clients make requests with the expected result to be JSON data.
879
+
* But in some cases the request may fail and result in an error HTML page being returned instead
880
+
* of the JSON. This will cause the client to throw a `SyntaxError` as a result
892
881
* of attempt to deserialize the non-JSON data.
893
-
* While the contents of the response may contain sensitive information, there may be a reason
894
-
* for failure embedded. This function attempts to extract that reason.
895
882
*
896
-
* Example error message before extracting:
897
-
* "Unexpected token '<', "<html><bod"... is not valid JSON Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object."
883
+
* But within the `SyntaxError` instance is the real reason for the failure.
884
+
* This class attempts to extract the underlying issue from the SyntaxError.
898
885
*
899
-
* If the reason cannot be found or the error is not a SyntaxError, return undefined.
886
+
* Example SyntaxError message before extracting the underlying issue:
887
+
* - "Unexpected token '<', "<html><bod"... is not valid JSON Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object."
888
+
* Once we extract the real error message from the hidden field, `$response.reason`, we get messages similar to:
889
+
* - "SDK Client unexpected error response: data response code: 403, data reason: Forbidden | Unexpected ..."
0 commit comments