add diagnostics for failures
This commit is contained in:
parent
9e8198cee4
commit
c056dbb0ff
16
src/aws.zig
16
src/aws.zig
|
@ -19,6 +19,18 @@ pub const Options = struct {
|
||||||
|
|
||||||
/// Used for testing to provide consistent signing. If null, will use current time
|
/// Used for testing to provide consistent signing. If null, will use current time
|
||||||
signing_time: ?i64 = null,
|
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()
|
/// 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();
|
defer response.deinit();
|
||||||
if (response.response_code != options.success_http_code) {
|
if (response.response_code != options.success_http_code) {
|
||||||
try reportTraffic(options.client.allocator, "Call Failed", aws_request, response, log.err);
|
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;
|
return error.HttpFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user