@@ -193,18 +193,31 @@ def POST(self, key): # noqa: PLR0915
193193 raise web .seeother (redirect_url )
194194
195195 if action == 'return' :
196- # Suppress PatronAccessException: the loan may have already expired
197- # on the IA side. Either way, proceed with redirect and confirmation.
198- with contextlib .suppress (lending .PatronAccessException ):
196+ try :
199197 lending .s3_loan_api (s3_keys , ocaid = edition .ocaid , action = 'return_loan' )
198+ except lending .PatronAccessException :
199+ # Loan may have already expired — check status before claiming success
200+ pass
200201 stats .increment ('ol.loans.return' )
201202 edition .update_loan_status ()
202203 user .update_loan_status ()
203- title = edition .title or _ ('this book' )
204- add_flash_message (
205- 'success' ,
206- _ ('You have successfully returned %s.' ) % title ,
207- )
204+
205+ if user .has_borrowed (edition ):
206+ # The return failed and they still have the loan
207+ add_flash_message (
208+ 'error' ,
209+ _ (
210+ 'Unable to return %s. Please try again later or contact info@archive.org.'
211+ )
212+ % (edition .title or _ ('this book' )),
213+ )
214+ else :
215+ # The return succeeded or the loan was already expired/gone
216+ title = edition .title or _ ('this book' )
217+ add_flash_message (
218+ 'success' ,
219+ _ ('%s has been returned.' ) % title ,
220+ )
208221 raise web .seeother (edition_redirect )
209222 elif action == 'join-waitinglist' :
210223 lending .get_cached_user_waiting_loans .memcache_delete (
0 commit comments