1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00
zap/examples/senderror/senderror.zig
geemili 5f4b7957dc fix: use error return trace in senderror
This should produce more usable error messages. The error messages before
this were pointing at zap runtime functions, instead of at the code that
produced the error.
2024-04-18 16:16:15 -06:00

28 lines
600 B
Zig

const std = @import("std");
const zap = @import("zap");
fn MAKE_MEGA_ERROR() !void {
return error.MEGA_ERROR;
}
fn MY_REQUEST_HANDLER(r: zap.Request) void {
MAKE_MEGA_ERROR() catch |err| {
r.sendError(err, if (@errorReturnTrace()) |t| t.* else null, 505);
};
}
pub fn main() !void {
var listener = zap.HttpListener.init(.{
.port = 3000,
.on_request = MY_REQUEST_HANDLER,
.log = true,
});
try listener.listen();
std.debug.print("Listening on 0.0.0.0:3000\n", .{});
zap.start(.{
.threads = 2,
.workers = 2,
});
}