Skip to content

Commit efb8c8c

Browse files
committed
Errors: Handle 404 while doing HTTP Requests
Closes #7
1 parent 62302f6 commit efb8c8c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/zigdcore.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ pub fn install_zig(allocator: std.mem.Allocator, zigd_path: []const u8, download
3939
try req.finish();
4040
try req.wait();
4141

42-
if (req.response.status != .ok)
42+
if (req.response.status != .ok) {
43+
std.log.err(
44+
\\
45+
\\Fetching the version failed!
46+
\\Does the version still exist in zig builds?
47+
\\Is the version correct?
48+
\\Response Code: {s} {d}
49+
, .{ req.response.status.phrase() orelse "???", req.response.status });
4350
return error.ResponseWasNotOk;
51+
}
4452

4553
const temp_dir_path = try std.fs.path.join(allocator, &.{ zigd_path, "tmp" });
4654
defer allocator.free(temp_dir_path);
@@ -155,8 +163,13 @@ pub fn fetchMaster(allocator: std.mem.Allocator, zigd_path: []const u8, allow_ca
155163

156164
const resp = req.response;
157165

158-
if (resp.status != .ok)
166+
if (resp.status != .ok) {
167+
std.log.err("Fetching the index failed\nResponse Code: {s} {d}", .{
168+
req.response.status.phrase() orelse "???",
169+
req.response.status,
170+
});
159171
return error.ResponseWasNotOk;
172+
}
160173

161174
const body = try req.reader().readAllAlloc(allocator, std.math.maxInt(usize));
162175
defer allocator.free(body);

0 commit comments

Comments
 (0)