-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor circulation exceptions (PP-991) #1694
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1694 +/- ##
==========================================
+ Coverage 90.08% 90.21% +0.12%
==========================================
Files 245 245
Lines 28170 28182 +12
Branches 6422 6446 +24
==========================================
+ Hits 25377 25424 +47
+ Misses 1848 1822 -26
+ Partials 945 936 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
c488ce0
to
cce6f32
Compare
pass | ||
|
||
|
||
class WorkflowException(BibliothecaException): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't being used anywhere.
@@ -894,23 +909,7 @@ def date_from_subtag(self, tag, key, required=True): | |||
return self.parse_date(value) | |||
|
|||
|
|||
class BibliothecaException(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced this exception with RemoteInitiatedServerError
, so that we get problem details from all the exceptions thrown by the Bibliotecha API.
@@ -416,7 +424,7 @@ def checkout( | |||
"User validation against Enki server with %s / %s was unsuccessful." | |||
% (patron.authorization_identifier, pin) | |||
) | |||
raise AuthorizationFailedException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only place that we used AuthorizationFailedException
, everywhere else used PatronAuthorizationFailedException
and it had the same problem detail, so I removed AuthorizationFailedException
.
@@ -57,7 +57,7 @@ | |||
|
|||
NO_ACCEPTABLE_FORMAT = pd( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status codes here were changed because the only place that used these ProblemDetails
was the loans controller exception handler, where they were called like this:
CANNOT_FULFILL.with_debug(str(e), status_code=e.status_code)
So they always had the status code of the exception, rather then the status code associated with the ProblemDetail
. This let me drop the status code on the exceptions and just use the one on the ProblemDetail.
This refactors how we are handling CirculationExceptions, so they all inherit from BaseProblemDetailException and are able to be turned into a ProblemDetail.
91db69b
to
0da3ac8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Description
This refactors how we are handling
CirculationExceptions
, so they all inherit fromBaseProblemDetailException
and are able to be turned into a ProblemDetail. This lets us simplify the exception handlers in the Loans controller to catch anyCirculationException
that the Circulation APIs might throw, and return the appropriate ProblemDetail, instead of continuing to grow the huge list of different Exceptions and actions we were handling.Motivation and Context
Reviewing the list of unhandled exceptions we are seeing in production, multiple in the top 10 were CirculationExceptions that were not in the
Except
block, or were handled for some actions likeborrow
but not others likehold
. This PR makes the handling we have here more consistent.Having a base class
BaseProblemDetailException
also makes it easier to know if we are able to turn an exception into a ProblemDetail or not.How Has This Been Tested?
Checklist