From e45599e9ecff1bd9f7e42d1f1073c854386f848c Mon Sep 17 00:00:00 2001 From: Medvidek77 Date: Wed, 2 Apr 2025 22:06:02 +0200 Subject: [PATCH] Fixed arguments statement --- src/main.zig | 10 ++++++---- src/url.zig | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.zig b/src/main.zig index 9aa9f8d..ae133f6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,9 +14,11 @@ pub fn main() !void { const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); - - if (eql(u8, args[1], "help")) { - dbg_print("Help :)\n", .{}); + + if (args.len > 1) { + if (eql(u8, args[1], "help")) { + dbg_print("Help :)\n", .{}); + } } const data = try url.fetch(allocator, "https://tidal.401658.xyz/track/?id=286266927&quality=LOSSLESS"); @@ -24,4 +26,4 @@ pub fn main() !void { try json.extract(allocator, data); -} \ No newline at end of file +} diff --git a/src/url.zig b/src/url.zig index e926aea..c36d77e 100644 --- a/src/url.zig +++ b/src/url.zig @@ -1,4 +1,5 @@ const std = @import("std"); + const dbg_print = std.debug.print; @@ -24,6 +25,10 @@ pub fn fetch(allocator: std.mem.Allocator, url: []const u8) ![]u8 { const body = try req.reader().readAllAlloc(allocator, 1024 * 64); - return body; + if (req.response.status == .ok) { + return body; + }else{ + return error.Unexpected; + } }