Print error return traces on error

This commit is contained in:
jaina heartles 2022-12-09 22:39:19 -08:00
parent 3cdd695948
commit 522b456939
1 changed files with 5 additions and 2 deletions

View File

@ -201,7 +201,7 @@ pub fn CatchErrors(comptime ErrorHandler: type) type {
return self.error_handler.handle(
req,
res,
addField(ctx, "err", err),
addField(addField(ctx, "err", err), "err_trace", @errorReturnTrace()),
next,
);
};
@ -218,7 +218,10 @@ pub fn catchErrors(error_handler: anytype) CatchErrors(@TypeOf(error_handler)) {
pub const default_error_handler = struct {
fn handle(_: @This(), req: anytype, res: anytype, ctx: anytype, _: anytype) !void {
const should_log = !@import("builtin").is_test;
if (should_log) std.log.err("Error {} on uri {s}", .{ ctx.err, req.uri });
if (should_log) {
std.log.err("Error {} on uri {s}", .{ ctx.err, req.uri });
std.log.debug("Additional details: {?}", .{ctx.err_trace});
}
// Tell the server to close the connection after this request
res.should_close = true;