summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-12-02 12:24:13 +0100
committerAzul <azul@riseup.net>2016-12-02 12:24:13 +0100
commit0aa101524270c0c398fe17c287d51927f810e499 (patch)
treeaed9cc67f5711352e86d8314a4718c777a23cc43 /lib
parent65600992f5317ec8889428001313e36629b1e877 (diff)
debug: raise error on 401
This will get us more debug info in the logs if it happens again
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/couch_db/source.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/nickserver/couch_db/source.rb b/lib/nickserver/couch_db/source.rb
index 7c3ad95..dd29c2a 100644
--- a/lib/nickserver/couch_db/source.rb
+++ b/lib/nickserver/couch_db/source.rb
@@ -6,17 +6,27 @@ require 'nickserver/couch_db/response'
require 'nickserver/config'
module Nickserver::CouchDB
+ class Error < StandardError; end
+
class Source < Nickserver::Source
VIEW = '/_design/Identity/_view/pgp_key_by_email'
+ UNEXPECTED_RESPONSE_CODES = [401, 500]
def query(nick)
status, body = adapter.get url, query: query_for(nick)
+ handle_unexpected_responses(status, body)
Response.new(nick, status: status, body: body)
end
protected
+ def handle_unexpected_responses(status, body)
+ if UNEXPECTED_RESPONSE_CODES.include? status
+ raise Error.new("Couch responded with #{status}: #{body}")
+ end
+ end
+
def url
Nickserver::Config.couch_url + VIEW
end