Handle authorization error when renewing a stale loan#2133
Merged
Conversation
When a loan becomes non-renewable between page load and the member clicking "Renew Loan" (e.g. staff checks the item back in), the authorization check raises a Pundit::NotAuthorizedError that was surfacing as a 500. Now it redirects back with a friendly warning.
jim
approved these changes
Mar 27, 2026
Member
jim
left a comment
There was a problem hiding this comment.
Thanks for fixing this fun race condition!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Rescues
Pundit::NotAuthorizedErrorin the account renewals controller and redirects the member back to their loans page with a warning message instead of showing a 500 error.Why it is important
A member hit a 500 when they clicked "Renew Loan" on a loan that staff had checked in seconds earlier. This is a natural race condition — the page showed the Renew button, but by the time they clicked it the loan was already ended. This change handles that gracefully.
Implementation notes
The race window is small but real — in the observed case it was ~12 seconds between check-in and the renewal attempt. Rather than adding broader Pundit error handling across all account controllers, this rescue is scoped to just the renewals action where the stale-page scenario is expected.