add diagnostics for failures
Some checks failed
AWS-Zig Build / build-zig-amd64-host (push) Successful in 1m31s
aws-zig mach nominated build / build-zig-nominated-mach-latest (push) Successful in 1m30s
aws-zig nightly build / build-zig-nightly (push) Failing after 26s

This commit is contained in:
Emil Lerch 2024-08-23 16:00:53 -07:00
parent 9e8198cee4
commit c056dbb0ff
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -19,6 +19,18 @@ pub const Options = struct {
/// Used for testing to provide consistent signing. If null, will use current time
signing_time: ?i64 = null,
diagnostics: ?*Diagnostics = null,
};
pub const Diagnostics = struct {
http_code: i64,
response_body: []const u8,
allocator: std.mem.Allocator,
pub fn deinit(self: *Diagnostics) void {
self.allocator.free(self.response_body);
self.response_body = undefined;
}
};
/// Using this constant may blow up build times. Recommed using Services()
@ -272,6 +284,10 @@ pub fn Request(comptime request_action: anytype) type {
defer response.deinit();
if (response.response_code != options.success_http_code) {
try reportTraffic(options.client.allocator, "Call Failed", aws_request, response, log.err);
if (options.diagnostics) |d| {
d.http_code = response.response_code;
d.response_body = try d.allocator.dupe(u8, response.body);
}
return error.HttpFailure;
}