uploads: improve error messages.
Improve upload error messages when downloading an URL fails, or it isn't an image or video file.
This commit is contained in:
@@ -147,7 +147,7 @@ module Danbooru
|
||||
def download_media(url, file: Tempfile.new("danbooru-download-", binmode: true))
|
||||
response = get(url)
|
||||
|
||||
raise DownloadError, "Downloading #{response.uri} failed with code #{response.status}" if response.status != 200
|
||||
raise DownloadError, "#{url} failed with code #{response.status}" if response.status != 200
|
||||
raise FileTooLargeError, "File size too large (size: #{response.content_length.to_i.to_formatted_s(:human_size)}; max size: #{@max_size.to_formatted_s(:human_size)})" if @max_size && response.content_length.to_i > @max_size
|
||||
|
||||
size = 0
|
||||
|
||||
@@ -219,9 +219,7 @@ module Sources
|
||||
|
||||
# Download the file at the given url, or at the main image url by default.
|
||||
def download_file!(download_url = image_url)
|
||||
raise DownloadError, "Download failed: couldn't find download url for #{url}" if download_url.blank?
|
||||
response, file = http_downloader.download_media(download_url)
|
||||
raise DownloadError, "Download failed: #{download_url} returned error #{response.status}" if response.status != 200
|
||||
file
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user