Skip to content

Commit

Permalink
Debug 502 Faraday Error
Browse files Browse the repository at this point in the history
Refactor user_invite.rb to handle API errors
  • Loading branch information
ekumachidi committed Mar 15, 2024
1 parent e1f1759 commit c8fd5d8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions app/services/schools/dfe_sign_in_api/user_invite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ def create
def response
raise ApiDisabled unless enabled?

resp = faraday.post(endpoint) do |req|
req.headers['Authorization'] = "bearer #{token}"
req.headers['Content-Type'] = 'application/json'
req.body = payload.to_json
end
begin
resp = faraday.post(endpoint) do |req|
req.headers['Authorization'] = "bearer #{token}"
req.headers['Content-Type'] = 'application/json'
req.body = payload.to_json
end

if resp.success?
return resp.body
else
raise "HTTP Error: #{resp.status} - #{resp.reason_phrase}\n#{resp.body}"
end

resp.body
rescue StandardError => e
raise "Request Failed: #{e.message}\n#{e.backtrace.join("\n")}"
end
end

def service_id
Expand Down

0 comments on commit c8fd5d8

Please sign in to comment.