Properly handle non-200 responses on multi-url requests #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, multi-url requests throw a
ValueError
when constructing the return list if the api requests returns anything other than a 200 response. The error happens specifically in this code:When the status code isn't
200
(and it's a multi-url request), thedata
value is assigned to a dictionary (as opposed the list/json array you'd expect from a200
response). When passed tomap(lambda url, data: Url(data, method, url), url_or_urls, data)
,map
iterates throughdata
andurl_or_urls
in parallel. Under successful200
responses,data
andurl_or_urls
are lists of equal length. In any other case,data
is a dictionary, somap
iterates through the keys of the dictionary. This causes exceptions because thedata
arg passed to the lambda func is now a string, not a dict.This fix works by simply copying the error data
len(url_or_urls)
times in a list, mimicking the list format expected in the downstreammap
function.