Skip to content

Commit

Permalink
Merge pull request #1133 from sul-dlss/hb-loans
Browse files Browse the repository at this point in the history
Add a honeybadger notice if we can't find a loan schedule for the policy
  • Loading branch information
jcoyne authored Jun 24, 2024
2 parents dc31184 + 883d9c9 commit 0676777
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/folio/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,19 @@ def effective_loan_policy
# NOTE: We need to fetch the latest loan policy to evaluate renewability. The loan policy returned
# with the loan is the policy at the time of checkout and could have changed in ways that impact
# eligibility for renewal.
def effective_loan_policy_id
def effective_loan_policy_id # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
cache_key = ['effective_loan_policy_id', item_type_id, loan_type_id, patron_type_id, location_id].join(':')
Rails.cache.fetch(cache_key, expires_in: 1.day) do
response = FolioClient.new.find_effective_loan_policy(item_type_id:,
loan_type_id:,
patron_type_id:,
location_id:)

unless response['loanPolicyId']
Honeybadger.notify('Unable to find effective loan policy for checkout',
context: { key:, cache_key:, response: })
end

response['loanPolicyId']
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/folio/loan_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def initialize(loan_policy:, due_date:, renewal_count:, hold_queue_length:)
@hold_queue_length = hold_queue_length
end

def name
loan_policy['name']
end

def loan_policy_interval
loan_policy.dig('loansPolicy', 'period', 'intervalId')
end
Expand Down Expand Up @@ -63,6 +67,8 @@ def due_date_from_schedule
Time.zone.now.between?(policy['from'], policy['to'])
end

Honeybadger.notify('No schedule found for loan policy', context: { loan_policy_name: name }) unless schedule

schedule['due'] if schedule
end

Expand Down

0 comments on commit 0676777

Please sign in to comment.