From a05899a1182f1927095f73ba0d9092a59e0d4530 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 29 Mar 2019 19:18:58 -0300 Subject: upload: accept non-200 codes This will try to JSON-decode any response, and if it succeds, will return it regardless of status code. If the body cannot be JSON-decoded, then the status code and URL are returned as an error. Fixes #975. --- src/luarocks/upload/api.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index dd0f1309..bb2197ee 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -237,10 +237,11 @@ function Api:request(url, params, post_params) if self.debug then util.printout(tostring(status)) end - if status ~= 200 then - return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url) + local pok, ret, err = pcall(json.decode, table.concat(out)) + if pok and ret then + return ret end - return json.decode(table.concat(out)) + return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url) end end -- cgit v1.2.3-55-g6feb