From 7f5e87568a6d322d44b2d82d101913c3f1ab4898 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 22 Jun 2020 22:51:36 -0500 Subject: [PATCH] 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. --- app/logical/danbooru/http.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/logical/danbooru/http.rb b/app/logical/danbooru/http.rb index 17f45ec21..ed25aa804 100644 --- a/app/logical/danbooru/http.rb +++ b/app/logical/danbooru/http.rb @@ -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