module Flucti module Utilities module ConnectionErrorHandling def self.included(target) target.module_eval do alias_method_chain :request, 'exception_handling' end end def request_with_exception_handling(*args, &block) request_without_exception_handling(*args, &block) rescue => e Handler.handle(e) or raise e end module Handler extend self, Utilities def handle(err) case err when WebService::BadGateway error! <<-MSG The VPS you attempted to perform an action on returned an error. It may be out of memory or disk space. Try running #{qcommand 'vps:run CMD="vmstat -s -S M"'} and #{qcommand 'vps:run CMD="df -h"'} respectively to determine whether it's the case or not. MSG when WebService::ServiceUnavailable, WebService::TimeoutError, Errno::ECONNREFUSED error! <<-MSG It looks like we are currently performing maintenance on our servers. Please retry later. MSG when WebService::GatewayTimeout error! <<-MSG The VPS you attempted to perform an action on did not respond in time. Please check its system load averages and retry. MSG when WebService::ServerError error! <<-MSG An error occurred while processing your request. We have be notified about this error and will work on fixing it. We apologize for the inconvenience. Please retry later. MSG end end end end end end