From d1449a6563cb53d415c107db2025ef2de5265644 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 14 Mar 2013 12:57:57 +0100 Subject: catch Errno's and RestClient errors and throw a more meaningful couchrest error --- core/lib/extensions/couchrest.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index 57bb837..f203426 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -23,6 +23,25 @@ module CouchRest end end + module Errors + class ConnectionFailed < CouchRestModelError; end + end + + module Connection + + module ClassMethods + + def use_database(db) + @database = prepare_database(db) + rescue RestClient::Unauthorized, + Errno::EHOSTUNREACH, + Errno::ECONNREFUSED => e + raise CouchRest::Model::Errors::ConnectionFailed.new(e.to_s) + end + end + + end + class Migrate def self.load_all_models_with_engines self.load_all_models_without_engines -- cgit v1.2.3