From ecfeaca7d4faee86ba85bf2f2e0bd50d4cacad9a Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 26 Oct 2019 13:01:08 -0500 Subject: [PATCH] iqdb: fix handling of error responses. Handle JSON error responses returned by IQDB: `{ "error": }`. --- app/logical/iqdb_proxy.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/logical/iqdb_proxy.rb b/app/logical/iqdb_proxy.rb index dc033eebf..e3254c996 100644 --- a/app/logical/iqdb_proxy.rb +++ b/app/logical/iqdb_proxy.rb @@ -36,7 +36,8 @@ class IqdbProxy def self.query(params) response = HTTParty.post("#{Danbooru.config.iqdbs_server}/similar", body: params, **Danbooru.config.httparty_options) - raise Error, "HTTP error: #{response.code} #{response.message}" unless response.success? + raise Error, "IQDB error: #{response.code} #{response.message}" unless response.success? + raise Error, "IQDB error: #{response.parsed_response["error"]}" if response.parsed_response.is_a?(Hash) raise Error, "IQDB error: #{response.parsed_response.first}" if response.parsed_response.try(:first).is_a?(String) response.parsed_response end