Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6fd5628

Browse files
committed
feat: better error messages
1 parent f593259 commit 6fd5628

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lua/leetcode/api/utils.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,29 @@ function utils.handle_res(out)
101101
msg = "curl failed",
102102
}
103103
elseif out.status >= 300 then
104+
local ok, msg = pcall(function()
105+
local dec = utils.decode(out.body)
106+
107+
if dec.error then return dec.error end
108+
109+
local tbl = {}
110+
for _, e in ipairs(dec.errors) do
111+
table.insert(tbl, e.message)
112+
end
113+
114+
return table.concat(tbl, "\n")
115+
end)
116+
104117
res = out.body
105118
err = {
106119
code = 0,
107120
status = out.status,
108121
response = out,
109-
msg = "http error " .. out.status,
122+
msg = "http error " .. out.status .. (ok and ("\n\n" .. msg) or ""),
110123
out = out.body,
111124
}
125+
126+
log.info(err)
112127
else
113128
res = utils.decode(out.body)
114129
end

0 commit comments

Comments
 (0)