Module: Deltacloud::Exceptions
- Included in:
- BaseDriver
- Defined in:
- lib/deltacloud/drivers/exceptions.rb
Defined Under Namespace
Modules: DSL
Classes: AcceptedButNotCompletedError, AuthenticationFailure, BackendError, Conflict, DeltacloudException, ExceptionDef, Exceptions, ForbiddenError, MethodNotAllowed, NotImplemented, NotSupported, ObjectNotFound, ProviderError, ProviderTimeout, UnknownMediaTypeError, ValidationFailure
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.exception_from_status(code, message) ⇒ Object
177
178
179
|
# File 'lib/deltacloud/drivers/exceptions.rb', line 177
def self.exception_from_status(code, message)
ExceptionDef.new(nil) { status code}.handler(StandardError.new(message))
end
|
.exceptions(&block) ⇒ Object
195
196
197
198
199
|
# File 'lib/deltacloud/drivers/exceptions.rb', line 195
def self.exceptions(&block)
@definitions ||= []
@definitions = Exceptions.new(&block).exception_definitions if block_given?
@definitions
end
|
.included(klass) ⇒ Object
214
215
216
|
# File 'lib/deltacloud/drivers/exceptions.rb', line 214
def self.included(klass)
klass.extend(DSL)
end
|
.logger(logger = nil) ⇒ Object
209
210
211
212
|
# File 'lib/deltacloud/drivers/exceptions.rb', line 209
def self.logger(logger=nil)
@logger = logger
@logger ||= ::Logger.new($stderr)
end
|
Instance Method Details
#safely(&block) ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/deltacloud/drivers/exceptions.rb', line 218
def safely(&block)
begin
block.call
rescue => e
self.class.exceptions.each do |definitions|
next unless definitions.any? e
if (new_exception = definitions.handler(e)) and new_exception.message
message = new_exception.message
end
message ||= e.message
raise definitions.handler(e) unless new_exception.nil?
end
raise BackendError.new(e, "Unhandled exception or status code (#{e.message})")
end
end
|