switch to http status enum
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 8m10s

This commit is contained in:
Emil Lerch 2026-02-04 00:37:27 -08:00
parent c1df6ef3a6
commit 5c7aed071f
Signed by: lobo
GPG key ID: A7B62D657EF764F8
4 changed files with 8 additions and 8 deletions

View file

@ -645,7 +645,7 @@ fn generateOperation(allocator: std.mem.Allocator, operation: smithy.ShapeInfo,
try outputIndent(child_state, writer);
try writer.print(".uri = \"{s}\",\n", .{trait.http.uri});
try outputIndent(child_state, writer);
try writer.print(".success_code = {d},\n", .{trait.http.code});
try writer.print(".success_code = @as(u10, {d}),\n", .{trait.http.code});
try outputIndent(state, writer);
_ = try writer.write("};\n\n");
}

View file

@ -82,7 +82,7 @@ const log = struct {
pub const Options = struct {
region: []const u8 = "aws-global",
dualstack: bool = false,
success_http_code: i64 = 200,
success_http_status: std.http.Status = .ok,
client: Client,
credential_options: credentials.Options = .{},
@ -92,7 +92,7 @@ pub const Options = struct {
};
pub const Diagnostics = struct {
http_code: i64,
response_status: std.http.Status,
response_body: []const u8,
allocator: std.mem.Allocator,
@ -305,7 +305,7 @@ pub fn Request(comptime request_action: anytype) type {
}
var rest_options = options;
rest_options.success_http_code = Action.http_config.success_code;
rest_options.success_http_status = @enumFromInt(Action.http_config.success_code);
return try Self.callAws(aws_request, rest_options);
}
@ -416,14 +416,14 @@ pub fn Request(comptime request_action: anytype) type {
);
defer response.deinit();
if (response.response_code != options.success_http_code and response.response_code != 404) {
if (response.response_code != options.success_http_status and response.response_code != .not_found) {
// If the consumer prrovided diagnostics, they are likely handling
// this error themselves. We'll not spam them with log.err
// output. Note that we may need to add additional information
// in diagnostics, as reportTraffic provides more information
// than what exists in the diagnostics data
if (options.diagnostics) |d| {
d.http_code = response.response_code;
d.response_status = response.response_code;
d.response_body = try d.allocator.dupe(u8, response.body);
} else try reportTraffic(
options.client.allocator,

View file

@ -363,7 +363,7 @@ pub const AwsHttp = struct {
log.debug("raw response body:\n{s}", .{aw.written()});
const rc = HttpResult{
.response_code = @intFromEnum(response.head.status),
.response_code = response.head.status,
.body = try aw.toOwnedSlice(),
.headers = try resp_headers.toOwnedSlice(self.allocator),
.allocator = self.allocator,

View file

@ -9,7 +9,7 @@ pub const Request = struct {
headers: []const std.http.Header = &.{},
};
pub const Result = struct {
response_code: u16, // actually 3 digits can fit in u10
response_code: std.http.Status,
body: []const u8,
headers: []const std.http.Header,
allocator: std.mem.Allocator,