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

Protocol tests issue 25 #3253

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public ErrorResponse Unmarshall(JsonUnmarshallerContext context)
{
// The error type can contain additional information, with ":" as a delimiter
// We are only interested in the initial part which is the error type
var index = errorType.IndexOf(":", StringComparison.Ordinal);
if(index != -1)
{
errorType = errorType.Substring(0, index);
}
type = errorType;
type = ParseType(errorType);
}
}

Expand All @@ -92,8 +87,7 @@ public ErrorResponse Unmarshall(JsonUnmarshallerContext context)
}

// strip extra data from type, leaving only the exception type name
type = type == null ? null : type.Substring(type.LastIndexOf("#", StringComparison.Ordinal) + 1);

type = type == null ? null : ParseType(type.Substring(type.LastIndexOf("#", StringComparison.Ordinal) + 1));
boblodgett marked this conversation as resolved.
Show resolved Hide resolved
// if no message was found create a generic message
if (string.IsNullOrEmpty(message))
{
Expand Down Expand Up @@ -133,6 +127,19 @@ public ErrorResponse Unmarshall(JsonUnmarshallerContext context)
return response;
}

// Parses the __type key returned in an error response by taking the first index of ":" and returning everything up to that index if it exists
// see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#operation-error-serialization
private static string ParseType(string type)
{
var index = type.IndexOf(":", StringComparison.Ordinal);
if (index != -1)
{
type = type.Substring(0, index);
}
return type;

}

private static void GetValuesFromJsonIfPossible(JsonUnmarshallerContext context, out string type, out string message, out string code)
{
code = null;
Expand Down