Skip to content

Handle authorization error when renewing a stale loan#2133

Merged
jim merged 1 commit intomainfrom
fix-renewal-authorization-500
Mar 27, 2026
Merged

Handle authorization error when renewing a stale loan#2133
jim merged 1 commit intomainfrom
fix-renewal-authorization-500

Conversation

@phinze
Copy link
Copy Markdown
Contributor

@phinze phinze commented Mar 27, 2026

What it does

Rescues Pundit::NotAuthorizedError in 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.

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.
Copy link
Copy Markdown
Member

@jim jim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this fun race condition!

@jim jim merged commit d033da9 into main Mar 27, 2026
10 checks passed
@jim jim deleted the fix-renewal-authorization-500 branch March 27, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants