From 7a4e21cc8229b5471a5a75d49bbd19db78da4e33 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Fri, 3 Jul 2026 15:53:19 +0300 Subject: [PATCH] `Updater`: gracefully handle known status codes --- src/Updater.zig | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Updater.zig b/src/Updater.zig index 3f5d7c924..4eb5277a9 100644 --- a/src/Updater.zig +++ b/src/Updater.zig @@ -119,15 +119,22 @@ pub fn inform(self: *Updater, writer: *std.Io.Writer) !void { try libcurl.curl_easy_setopt(conn._easy, .write_data, &ctx); // Make a request. - const status_int = conn.request(&self.config.http_headers) catch |err| { + const status_int = conn.perform() catch |err| { ctx.err catch |ctx_err| return ctx_err; return err; }; const status: std.http.Status = @enumFromInt(status_int); - if (status != .ok) { - return error.UnexpectedStatus; + switch (status) { + // Write what's received. + .ok => try writer.writeAll(ctx.buffer.items), + // Client failed. + .bad_request => try writer.writeAll("Versions format is invalid.\n"), + // Server failed. + .internal_server_error, + .service_unavailable, + => try writer.writeAll("Couldn't get the versions list from remote.\n"), + else => return error.UnexpectedStatus, } - try writer.writeAll(ctx.buffer.items); return writer.flush(); }