mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
Log error to output and add to data
This commit is contained in:
parent
b66073955d
commit
4d2bd0b86b
@ -8,6 +8,5 @@ const View = jetzig.views.View;
|
|||||||
pub fn index(request: *Request, data: *Data) anyerror!View {
|
pub fn index(request: *Request, data: *Data) anyerror!View {
|
||||||
var object = try data.object();
|
var object = try data.object();
|
||||||
try object.put("foo", data.string("hello"));
|
try object.put("foo", data.string("hello"));
|
||||||
// return error.OhNo;
|
|
||||||
return request.render(.ok);
|
return request.render(.ok);
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,7 @@ fn renderView(
|
|||||||
template: ?jetzig.TemplateFn,
|
template: ?jetzig.TemplateFn,
|
||||||
) !RenderedView {
|
) !RenderedView {
|
||||||
const view = matched_route.render(matched_route, request) catch |err| {
|
const view = matched_route.render(matched_route, request) catch |err| {
|
||||||
|
self.logger.debug("Encountered error: {s}", .{@errorName(err)});
|
||||||
switch (err) {
|
switch (err) {
|
||||||
error.OutOfMemory => return err,
|
error.OutOfMemory => return err,
|
||||||
else => return try self.internalServerError(request, err),
|
else => return try self.internalServerError(request, err),
|
||||||
@ -216,9 +217,10 @@ fn internalServerError(self: *Self, request: *jetzig.http.Request, err: anyerror
|
|||||||
request.response_data.reset();
|
request.response_data.reset();
|
||||||
var object = try request.response_data.object();
|
var object = try request.response_data.object();
|
||||||
try object.put("error", request.response_data.string(@errorName(err)));
|
try object.put("error", request.response_data.string(@errorName(err)));
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.view = jetzig.views.View{ .data = request.response_data, .status_code = .internal_server_error },
|
.view = jetzig.views.View{ .data = request.response_data, .status_code = .internal_server_error },
|
||||||
.content = "An unexpected error occurred.",
|
.content = "Internal Server Error\n",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ pub const TaggedStatusCode = union(StatusCode) {
|
|||||||
switching_protocols: StatusCodeType("101", "Switching Protocols"),
|
switching_protocols: StatusCodeType("101", "Switching Protocols"),
|
||||||
processing: StatusCodeType("102", "Processing"),
|
processing: StatusCodeType("102", "Processing"),
|
||||||
early_hints: StatusCodeType("103", "Early Hints"),
|
early_hints: StatusCodeType("103", "Early Hints"),
|
||||||
ok: StatusCodeType("200", "Ok"),
|
ok: StatusCodeType("200", "OK"),
|
||||||
created: StatusCodeType("201", "Created"),
|
created: StatusCodeType("201", "Created"),
|
||||||
accepted: StatusCodeType("202", "Accepted"),
|
accepted: StatusCodeType("202", "Accepted"),
|
||||||
non_authoritative_info: StatusCodeType("203", "Non Authoritative Information"),
|
non_authoritative_info: StatusCodeType("203", "Non Authoritative Information"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user