diff --git a/app/lib/nhs/pds.rb b/app/lib/nhs/pds.rb index c82043326..248289e78 100644 --- a/app/lib/nhs/pds.rb +++ b/app/lib/nhs/pds.rb @@ -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 @@ -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)