-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Error structure core components #986
Conversation
Add ErrorCodes Enum
1. To capture all exception and convert it to proper api error response 2. To check if error response are correct
Codecov Report
@@ Coverage Diff @@
## master #986 +/- ##
==========================================
- Coverage 93.30% 92.46% -0.84%
==========================================
Files 86 89 +3
Lines 3165 3200 +35
==========================================
+ Hits 2953 2959 +6
- Misses 212 241 +29
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Some more style issues.
…re already caught. Add base Exception and Error classes which can be extended upon if needed
…o `APIExceptionClass`
… into error-structure_core_components
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 looks fine to me. It's hard to think about the structure without example exceptions implemented to think through, but we can figure that out in later PRs.
I added some minor comments, please fix and merge yourself, no need for me to re-review.
|
||
from django.utils.encoding import force_str | ||
from rest_framework import status | ||
from rest_framework.exceptions import APIException as DRFApiException |
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 should be DRFAPIException
or something like OriginalAPIException
if the concatenated acronyms are hard to read, it's confusing to mix API
and Api
self.status_code = status_code | ||
|
||
|
||
class GenericApiError(APIException): |
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 should also be API
instead of Api
|
||
@unique | ||
class ErrorCodes(Enum): | ||
NonClassifiedError = 4999 |
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.
I think UnknownError
might be a bit clearer for this.
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 is more like saying we are able to get the detail of the error but haven't specified any error code for it.
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.
Maybe UnspecifiedCodeError
, then?
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.
That was my choice at first but felt like error code
hasn't been classified yet made sense, UnspecifiedCodeError
seems like error code has not been specified and there is an error related to that, but I think I will go with UnknownError
seems neutral.
return APIException(exc, ErrorCodes.NonClassifiedError.value) | ||
|
||
|
||
class APIException(DRFApiException): |
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.
Can we call ours MathesarAPIException
? It might be confusing to overload the original name for contributors who are used to working with DRF.
Rename `GenericApiError` to `GenericAPIError`
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.
I think it makes sense. Like @kgodey , I'd need to see it in action to provide more feedback.
Fixes #983
It adds the necessary components required for
ApiException
to properApiException
Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin