Module: Datacentred::Errors
- Defined in:
- lib/datacentred/error.rb
Overview
Behaviours and exceptions for recoverable errors.
Defined Under Namespace
Classes: Error, NotFound, Unauthorized, UnprocessableEntity
Class Method Summary collapse
-
.raise_unless_successful(status, body) ⇒ nil
Test server response and raise appropriate error if an error has been returned.
Class Method Details
.raise_unless_successful(status, body) ⇒ nil
Test server response and raise appropriate error if an error has been returned.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/datacentred/error.rb', line 8 def self.raise_unless_successful(status, body) return if status.to_s.start_with? "2" # 2xx err = errors[status] = body&.fetch("errors")&.first&.fetch("detail") if err raise err, || status.to_s else raise Error, "Error #{status}: #{}" end end |