Skip to content

Commit af3a02a

Browse files
committed
Catch fatal error on PATCH operation.
1 parent 7cf9e76 commit af3a02a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

lib/fhir_client/client.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def post(path, resource, headers)
399399
else
400400
headers.merge!(@security_headers) if @use_basic_auth
401401
@client.post(url, payload, headers) do |resp, request, result|
402-
FHIR.logger.info "POST - Request: #{request.to_json}, Response: #{resp.force_encoding('UTF-8')}"
402+
FHIR.logger.info "POST - Request: #{request.to_json}\nResponse:\nResponse Headers: #{scrubbed_response_headers(result.each_key {})} \nResponse Body: #{resp.force_encoding('UTF-8')}"
403403
request.args[:path] = url.gsub(@base_service_url, '')
404404
res = {
405405
code: result.code,
@@ -480,16 +480,30 @@ def patch(path, patchset, headers)
480480
@reply = FHIR::ClientReply.new(req, res)
481481
else
482482
headers.merge!(@security_headers) if @use_basic_auth
483-
# url = 'http://requestb.in/o8juy3o8'
484-
@client.patch(url, payload, headers) do |resp, request, result|
485-
FHIR.logger.info "PATCH - Request: #{request.to_json}, Response: #{resp.force_encoding('UTF-8')}"
486-
request.args[:path] = url.gsub(@base_service_url, '')
483+
begin
484+
@client.patch(url, payload, headers) do |resp, request, result|
485+
FHIR.logger.info "PATCH - Request: #{request.to_json}, Response: #{resp.force_encoding('UTF-8')}"
486+
request.args[:path] = url.gsub(@base_service_url, '')
487+
res = {
488+
code: result.code,
489+
headers: scrubbed_response_headers(result.each_key {}),
490+
body: resp
491+
}
492+
@reply = FHIR::ClientReply.new(request.args, res)
493+
end
494+
rescue => e
495+
req = {
496+
method: :patch,
497+
url: url,
498+
path: url.gsub(@base_service_url, ''),
499+
headers: headers,
500+
payload: payload
501+
}
487502
res = {
488-
code: result.code,
489-
headers: scrubbed_response_headers(result.each_key {}),
490-
body: resp
503+
body: e.message
491504
}
492-
@reply = FHIR::ClientReply.new(request.args, res)
505+
FHIR.logger.error "PATCH Error: #{e.message}"
506+
@reply = FHIR::ClientReply.new(req, res)
493507
end
494508
end
495509
end

0 commit comments

Comments
 (0)