summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-04-26 16:10:23 -0700
committerelijah <elijah@riseup.net>2015-04-26 16:10:23 -0700
commit02c2f59dd1725cc0bd83e346259d54ea46a5ba1f (patch)
treeef888414aaf43d6d6cebceb0b09f83d0f73e2c5e
parent726b3a8145eee81eb55faebdbec40ed0e1b4e819 (diff)
correctly log errors when restclient exceptions do not have a response.
-rw-r--r--files/couch-doc-update14
1 files changed, 10 insertions, 4 deletions
diff --git a/files/couch-doc-update b/files/couch-doc-update
index 62d04e6..4ae811e 100644
--- a/files/couch-doc-update
+++ b/files/couch-doc-update
@@ -41,14 +41,16 @@ def main
raise StandardError.new(result.inspect)
rescue StandardError => exc
db_without_password = db.to_s.sub(/:[^\/]*@/, ':PASSWORD_HIDDEN@')
+ indent = " "
log "ERROR: " + exc.to_s
- log " failed writing to #{db_without_password}/#{id}"
+ log indent + $@[0..4].join("\n#{indent}")
+ log indent + "Failed writing to #{db_without_password}/#{id}"
exit 1
end
def log(message)
$stderr.puts message
- Syslog.open do |logger|
+ Syslog.open('couch-doc-update') do |logger|
logger.log(Syslog::LOG_CRIT, message)
end
end
@@ -121,7 +123,9 @@ def update_document(db, doc, data)
doc.merge! data
db.save_doc(doc)
rescue RestClient::ExceptionWithResponse => e
- if [500, 422].include?(e.response.code)
+ if e.response.nil?
+ raise e
+ elsif [500, 422].include?(e.response.code)
raise if attempt > 5
attempt += 1
sleep 10
@@ -134,7 +138,9 @@ def create_document(db, doc_id, data)
data["_id"] = doc_id
db.save_doc(data)
rescue RestClient::ExceptionWithResponse => e
- if [500, 422].include?(e.response.code)
+ if e.response.nil?
+ raise e
+ elsif [500, 422].include?(e.response.code)
raise if attempt > 5
attempt += 1
sleep 10