From 0aa101524270c0c398fe17c287d51927f810e499 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 2 Dec 2016 12:24:13 +0100 Subject: debug: raise error on 401 This will get us more debug info in the logs if it happens again --- lib/nickserver/couch_db/source.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/nickserver/couch_db') 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 -- cgit v1.2.3