Skip to content

Commit

Permalink
add logging to RX endpoints (#11913)
Browse files Browse the repository at this point in the history
  • Loading branch information
aherzberg authored Mar 3, 2023
1 parent ebe4b4f commit fd759a9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/rx/middleware/response/rx_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RxParser < Faraday::Response::Middleware
# @return [Faraday::Env]
#
def on_complete(env)
Rails.logger.info('RX Error Debugging', response: env)
return unless env.response_headers['content-type']&.match?(/\bjson/)
# If POST for prescriptions is successful message body is irrelevant
# if it was not successul an exception would have already been raised
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,70 @@ module V0
class PrescriptionsController < ApplicationController
before_action { authorize :mhv_prescriptions, :access? }

# rubocop:disable Metrics/MethodLength
def index
resource = client.get_history_rxs
begin
resource = client.get_history_rxs

# Temporary logging for prescription bug investigation
resource.attributes.each do |p|
Rails.logger.info('MHV Prescription Response',
user: @current_user.uuid,
params: params, id: p[:prescription_id],
prescription: p)
end
rescue => e
Rails.logger.error(
'Mobile Prescription Upstream Index Error',
resource: resource, error: e, message: e.message, backtrace: e.backtrace
)
raise e
end

resource = params[:filter].present? ? resource.find_by(filter_params) : resource
resource = resource.sort(params[:sort])
page_resource, page_meta_data = paginate(resource.attributes)

render json: Mobile::V0::PrescriptionsSerializer.new(page_resource, page_meta_data)
serialized_prescription = Mobile::V0::PrescriptionsSerializer.new(page_resource, page_meta_data)

# Temporary logging for prescription bug investigation
serialized_prescription.to_hash[:data].each do |p|
Rails.logger.info('Mobile Prescription Response', user: @current_user.uuid, id: p[:id], prescription: p)
end

render json: serialized_prescription
end
# rubocop:enable Metrics/MethodLength

def refill
resource = client.post_refill_rxs(ids)

# Temporary logging for prescription bug investigation
Rails.logger.info('MHV Prescription Refill Response', user: @current_user.uuid, ids: ids, response: resource)

render json: Mobile::V0::PrescriptionsRefillsSerializer.new(@current_user.uuid, resource.body)
rescue => e
Rails.logger.error(
'Mobile Prescription Refill Error',
resource: resource, error: e, message: e.message, backtrace: e.backtrace
)
raise e
end

def tracking
resource = client.get_tracking_history_rx(params[:id])

# Temporary logging for prescription bug investigation
Rails.logger.info('MHV Prescription Tracking Response', user: @current_user.uuid, id: params[:id],
response: resource)

render json: Mobile::V0::PrescriptionTrackingSerializer.new(resource.data)
rescue => e
Rails.logger.error(
'Mobile Prescription Tracking Error',
resource: resource, error: e, message: e.message, backtrace: e.backtrace
)
raise e
end

private
Expand Down

0 comments on commit fd759a9

Please sign in to comment.