From c056dbb0ff062cda936a7e9a4d17290c99720901 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 23 Aug 2024 16:00:53 -0700 Subject: [PATCH] add diagnostics for failures --- src/aws.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/aws.zig b/src/aws.zig index 28d2cbe..f7d9f42 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -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; }