diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-29 19:18:58 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-29 19:21:57 -0300 |
| commit | a05899a1182f1927095f73ba0d9092a59e0d4530 (patch) | |
| tree | e5f35ddcf85445d2482ef6742bee4e51c06df9e4 | |
| parent | 973655f97869c7e27bb5cf23ac3ba58508451eee (diff) | |
| download | luarocks-a05899a1182f1927095f73ba0d9092a59e0d4530.tar.gz luarocks-a05899a1182f1927095f73ba0d9092a59e0d4530.tar.bz2 luarocks-a05899a1182f1927095f73ba0d9092a59e0d4530.zip | |
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.
| -rw-r--r-- | src/luarocks/upload/api.lua | 7 |
1 files changed, 4 insertions, 3 deletions
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) | |||
| 237 | if self.debug then | 237 | if self.debug then |
| 238 | util.printout(tostring(status)) | 238 | util.printout(tostring(status)) |
| 239 | end | 239 | end |
| 240 | if status ~= 200 then | 240 | local pok, ret, err = pcall(json.decode, table.concat(out)) |
| 241 | return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url) | 241 | if pok and ret then |
| 242 | return ret | ||
| 242 | end | 243 | end |
| 243 | return json.decode(table.concat(out)) | 244 | return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url) |
| 244 | end | 245 | end |
| 245 | 246 | ||
| 246 | end | 247 | end |
