Better error messages
This commit is contained in:
parent
44cb7017b2
commit
d27c38330b
1 changed files with 3 additions and 3 deletions
|
@ -50,7 +50,7 @@ fn respondJson(ctx: *http.server.Context, status: http.Status, value: anytype, a
|
|||
}
|
||||
|
||||
fn createNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
|
||||
const body = ctx.request.body orelse return respondJson(ctx, .bad_request, .{ .@"error" = "no note body provided" }, srv.alloc);
|
||||
const body = ctx.request.body orelse return respondJson(ctx, .bad_request, .{ .@"error" = "'content' cannot be empty" }, srv.alloc);
|
||||
var tokens = std.json.TokenStream.init(body);
|
||||
const info = try std.json.parse(api.CreateInfo(models.Note), &tokens, .{ .allocator = srv.alloc });
|
||||
defer std.json.parseFree(api.CreateInfo(models.Note), info, .{ .allocator = srv.alloc });
|
||||
|
@ -62,8 +62,8 @@ fn createNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !voi
|
|||
|
||||
fn getNote(srv: *RequestServer, ctx: *http.server.Context, args: RouteArgs) !void {
|
||||
const id_str = args.get("id") orelse return error.NotFound;
|
||||
const id = Uuid.parse(id_str) catch return respondJson(ctx, .bad_request, .{ .@"error" = "invalid id" }, srv.alloc);
|
||||
const note = (try srv.api.getNote(id, srv.alloc)) orelse return error.NotFound;
|
||||
const id = Uuid.parse(id_str) catch return respondJson(ctx, .bad_request, .{ .@"error" = "Invalid UUID" }, srv.alloc);
|
||||
const note = (try srv.api.getNote(id, srv.alloc)) orelse return respondJson(ctx, .not_found, .{ .@"error" = "Note not found" }, srv.alloc);
|
||||
defer api.free(srv.alloc, note);
|
||||
|
||||
try respondJson(ctx, .ok, note, srv.alloc);
|
||||
|
|
Loading…
Reference in a new issue