danbooru::http: raise exception on failed downloads.

Restore behavior from a6994cd4d, it breaks tests when they try to the
response body from a fake 599 response.
This commit is contained in:
evazion
2020-06-22 22:51:36 -05:00
parent 31802fb666
commit 7f5e87568a

View File

@@ -7,6 +7,7 @@ require "danbooru/http/session"
module Danbooru
class Http
class DownloadError < StandardError; end
class FileTooLargeError < StandardError; end
DEFAULT_TIMEOUT = 10
@@ -110,6 +111,7 @@ module Danbooru
end
def download_response(response, file: Tempfile.new("danbooru-download-", binmode: true))
raise DownloadError, "Downloading #{response.uri} failed with code #{response.status}" if response.status != 200
raise FileTooLargeError, response if @max_size && response.content_length.to_i > @max_size
size = 0