Skip to content

Commit 78baec9

Browse files
committed
Add more logging
1 parent 820923d commit 78baec9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/server.zig

+7
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const SearchResultsJSON = struct {
132132

133133
fn getId(req: *httpz.Request, res: *httpz.Response, send_body: bool) !?u32 {
134134
const id_str = req.param("id") orelse {
135+
log.warn("missing id parameter", .{});
135136
if (send_body) {
136137
try writeErrorResponse(400, error.MissingId, req, res);
137138
} else {
@@ -140,6 +141,7 @@ fn getId(req: *httpz.Request, res: *httpz.Response, send_body: bool) !?u32 {
140141
return null;
141142
};
142143
return std.fmt.parseInt(u32, id_str, 10) catch |err| {
144+
log.warn("invalid id parameter: {}", .{err});
143145
if (send_body) {
144146
try writeErrorResponse(400, err, req, res);
145147
} else {
@@ -151,6 +153,7 @@ fn getId(req: *httpz.Request, res: *httpz.Response, send_body: bool) !?u32 {
151153

152154
fn getIndex(ctx: *Context, req: *httpz.Request, res: *httpz.Response, send_body: bool) !?*Index {
153155
const index_name = req.param("index") orelse {
156+
log.warn("missing index parameter", .{});
154157
if (send_body) {
155158
try writeErrorResponse(400, error.MissingIndexName, req, res);
156159
} else {
@@ -159,6 +162,7 @@ fn getIndex(ctx: *Context, req: *httpz.Request, res: *httpz.Response, send_body:
159162
return null;
160163
};
161164
const index = ctx.indexes.getIndex(index_name) catch |err| {
165+
log.warn("error during getIndex: {}", .{err});
162166
if (err == error.IndexNotFound) {
163167
if (send_body) {
164168
try writeErrorResponse(404, err, req, res);
@@ -243,6 +247,7 @@ fn writeErrorResponse(status: u16, err: anyerror, req: *httpz.Request, res: *htt
243247

244248
fn getRequestBody(comptime T: type, req: *httpz.Request, res: *httpz.Response) !?T {
245249
const content = req.body() orelse {
250+
log.warn("no body", .{});
246251
try writeErrorResponse(400, error.NoContent, req, res);
247252
return null;
248253
};
@@ -255,12 +260,14 @@ fn getRequestBody(comptime T: type, req: *httpz.Request, res: *httpz.Response) !
255260
switch (content_type) {
256261
.json => {
257262
return json.parseFromSliceLeaky(T, req.arena, content, .{}) catch |err| {
263+
log.warn("json error: {}", .{err});
258264
try writeErrorResponse(400, err, req, res);
259265
return null;
260266
};
261267
},
262268
.msgpack => {
263269
return msgpack.decodeFromSliceLeaky(T, req.arena, content) catch |err| {
270+
log.warn("msgpack error: {}", .{err});
264271
try writeErrorResponse(400, err, req, res);
265272
return null;
266273
};

0 commit comments

Comments
 (0)