Module: PatchRetention::Util
- Included in:
- Contacts::Delete, Contacts::Find, Contacts::FindOrCreate, Contacts::Update, Events::Create, Events::Find
- Defined in:
- lib/patch_retention/util.rb
Overview
The Util module provides utility methods used across the PatchRetention library. These methods are designed to handle common tasks such as error handling and response parsing.
Instance Method Summary collapse
-
#parse_error_message(response) ⇒ String
Parses the error message from the response.
-
#raise_error_if_present {|response| ... } ⇒ response
Raises a PatchRetention::Error if the yielded block’s response status is not 200.
Instance Method Details
#parse_error_message(response) ⇒ String
Parses the error message from the response. Raises a PatchRetention::Error if the response status is 502 and the body is blank.
25 26 27 28 29 30 31 32 |
# File 'lib/patch_retention/util.rb', line 25 def (response) if response.status == 502 && response.body.blank? raise PatchRetention::Error, "Internal Server Error: Patch API" end JSON.parse(response.body)["error"] end |
#raise_error_if_present {|response| ... } ⇒ response
Raises a PatchRetention::Error if the yielded block’s response status is not 200.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/patch_retention/util.rb', line 10 def raise_error_if_present response = yield raise PatchRetention::Error, (response) unless response.status.between?(200, 206) begin JSON.parse(response.body) rescue JSON::ParserError true end end |