aws/internal/error_code
Shared modeled-error-code extraction. AWS error responses carry the
modeled error code (the Smithy shape’s local name) in one of three
places, depending on protocol: the X-Amzn-Errortype header
(awsJson*, restJson1), a JSON body __type / code field, or a
restXml <Code> element. This module pulls that local shape name
out — namespace prefix, URI suffix, and Smithy [Charlie,foo]
disambiguation suffix all stripped.
Both the retry middleware (aws/retry), which inspects the raw
Response inside the retry loop before any typed parsing, and the
runtime (aws/internal/client/runtime), which builds the typed
ServiceError after the loop, need the same extraction — so it
lives here once rather than being duplicated across the two layers.
Values
pub fn from_header_value_and_body(
error_type_header: Result(String, Nil),
body: BitArray,
) -> String
Like from_headers_and_body but taking the x-amzn-errortype
header value as a pre-resolved Result. The retry layer holds a
Response (not a header dict) and reads the header via
response.get_header, so this entry point lets it reuse the exact
same extraction without rebuilding a dict.
pub fn from_headers_and_body(
headers: dict.Dict(String, String),
body: BitArray,
) -> String
Pull the wire-error-type local name out of an error response’s
already-lowercased headers + body. Prefers the x-amzn-errortype
header (restJson1, awsJson*), then falls back to the body’s
__type / code (JSON) or <Code> (restXml). Returns the local
shape name with namespace / URI / disambiguation suffixes stripped,
or "Unknown" when nothing matches.
pub fn normalise(raw: String) -> String
Strip an error-type wire value down to its local Smithy shape name:
drop any Type:uri suffix, any , disambiguation list, and any
namespace# prefix. Exposed so callers that already hold a raw
header value (not a full response) can normalise it consistently.