Skip to content

Commit

Permalink
Record PDS error responses in Sentry
Browse files Browse the repository at this point in the history
This makes it easier to debug issues by including a breadcrumb
containing the response from PDS in Sentry.
  • Loading branch information
thomasleese committed Dec 16, 2024
1 parent ee13dba commit 79c1c7d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/lib/nhs/pds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_patient(nhs_number)
"personal-demographics/FHIR/R4/Patient/#{nhs_number}"
)
rescue Faraday::BadRequestError => e
add_sentry_breadcrumb(e)

if is_error?(e, "INVALID_RESOURCE_ID")
raise InvalidNHSNumber, nhs_number
else
Expand All @@ -56,10 +58,23 @@ def search_patients(attributes)
"personal-demographics/FHIR/R4/Patient",
attributes
)
rescue Faraday::BadRequestError => e
add_sentry_breadcrumb(e)
raise
end

private

def add_sentry_breadcrumb(error)
crumb =
Sentry::Breadcrumb.new(
category: "http.response",
data: error.response,
level: "error"
)
Sentry.add_breadcrumb(crumb)
end

def is_error?(error, code)
response = JSON.parse(error.response_body)

Expand Down

0 comments on commit 79c1c7d

Please sign in to comment.