Sha256: 8bdd9ca707369b2f78cbd60811331ae1ce7939e9dc7e9220e61066ed832c1846
Contents?: true
Size: 666 Bytes
Versions: 2
Compression:
Stored size: 666 Bytes
Contents
module Datacentred class Error < StandardError def self.raise_unless_successful(status, body) return if status.to_s.start_with? "2" # 2xx err = Datacentred::errors[status] message = body&.fetch("errors")&.first&.fetch("detail") if err raise err, message else raise Datacentred::Error, "Error #{status}: #{message}" end end end class NotFoundError < StandardError; end class UnprocessableEntity < StandardError; end class Unauthorized < StandardError; end private def self.errors { 401 => Unauthorized, 404 => NotFoundError, 422 => UnprocessableEntity } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
datacentred-0.1.1pre | lib/datacentred/error.rb |
datacentred-0.1.0pre | lib/datacentred/error.rb |