Module: Clicksign::ErrorHandler
- Defined in:
- lib/clicksign/error_handler.rb
Class Method Summary collapse
Class Method Details
.call(response) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/clicksign/error_handler.rb', line 5 def self.call(response) case response.code.to_i when 200..299 then nil when 401, 403 then raise AuthenticationError, (response) when 404 then raise NotFoundError, (response) when 400, 422 then raise ValidationError, (response) when 409 then raise ConflictError, (response) when 429 then raise RateLimitError, (response) when 500..599 then raise ServerError, (response) else raise Error, (response) end end |
.extract_message(response) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/clicksign/error_handler.rb', line 18 def self.(response) body = JSON.parse(response.body) return response. unless body.is_a?(Hash) errors = body['errors'] return response. if errors.nil? || !errors.is_a?(Array) errors.filter_map { |e| e['detail'] || e['title'] }.join(', ') rescue JSON::ParserError response. end |