diff options
author | azul <azul@riseup.net> | 2016-12-02 11:25:35 +0000 |
---|---|---|
committer | azul <azul@riseup.net> | 2016-12-02 11:25:35 +0000 |
commit | 8bfd27e0c851e9786110be4e6485635f769d853f (patch) | |
tree | aed9cc67f5711352e86d8314a4718c777a23cc43 /lib/nickserver/couch_db | |
parent | 244d8a4702f98619078c0e09e485d7e1944e5013 (diff) | |
parent | 0aa101524270c0c398fe17c287d51927f810e499 (diff) |
Merge branch 'bugfix/couch-auth' into 'master'
bugfix: use user:password@ prefix in http basic auth
See merge request !9
Diffstat (limited to 'lib/nickserver/couch_db')
-rw-r--r-- | lib/nickserver/couch_db/source.rb | 10 |
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 |