summaryrefslogtreecommitdiff
path: root/lib/nickserver/couch_db
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nickserver/couch_db')
-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