Skip to content

Commit

Permalink
Include url and params in POST exceptions. Closes #305
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 15, 2024
1 parent 1763ce1 commit bdae885
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/noticed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class ValidationError < StandardError
class ResponseUnsuccessful < StandardError
attr_reader :response

def initialize(response, url)
def initialize(response, url, args)
@response = response
@url = url
@args = args

super("POST request to #{url} returned #{response.code} response:\n#{response.body.inspect}")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/noticed/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def post_request(url, args = {})
response = http.request(request)
logger.debug("Response: #{response.code}: #{response.body.inspect}")

raise ResponseUnsuccessful.new(request, response, http) unless response.code.start_with?("20")
raise ResponseUnsuccessful.new(response, url, args) unless response.code.start_with?("20")

response
end
Expand Down
6 changes: 4 additions & 2 deletions lib/noticed/delivery_methods/vonage_sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class VonageSms < DeliveryMethod
required_options :json

def deliver
response = post_request url, headers: evaluate_option(:headers), json: evaluate_option(:json)
raise ResponseUnsuccessful.new(response) if JSON.parse(response.body).dig("messages", 0, "status") != "0"
headers = evaluate_option(:headers)
json = evaluate_option(:json)
response = post_request url, headers: headers, json: json
raise ResponseUnsuccessful.new(response, url, headers: headers, json: json) if JSON.parse(response.body).dig("messages", 0, "status") != "0"
end

def url
Expand Down

0 comments on commit bdae885

Please sign in to comment.