-
Notifications
You must be signed in to change notification settings - Fork 0
[MCC-1487221] - Error Handling #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f886b48
feat: added error handling framework across layers, commented all tes…
slingampalli-mdsol 2bc2b25
feat: temporarily disabling tests until refactoring is completed
slingampalli-mdsol c459d16
fix: updated mappers to raise exceptions
slingampalli-mdsol bf86210
fix: retaining existing mapped DataConnectError
slingampalli-mdsol b56d97c
Merge branch 'main' into features/MCC-1487221-1
slingampalli-mdsol 5fa018a
fix: disabling typecheck temporarily
slingampalli-mdsol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """Service-layer error translation utilities. | ||
|
|
||
| Provides a single function to map transport-layer ``TransportError`` subtypes | ||
| into the corresponding public ``DataConnectError`` subtypes that callers catch. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataconnect.exceptions import ( | ||
| AuthenticationError, | ||
| AuthorizationError, | ||
| DataConnectError, | ||
| NotFoundError, | ||
| ServerError, | ||
| ValidationError, | ||
| ) | ||
| from dataconnect.exceptions import ( | ||
| ErrorDetail as DataConnectErrorDetail, | ||
| ) | ||
| from dataconnect.transport.errors import ( | ||
| TransportAuthenticationError, | ||
| TransportAuthorizationError, | ||
| TransportError, | ||
| TransportNotFoundError, | ||
| TransportServerError, | ||
| TransportValidationError, | ||
| ) | ||
|
|
||
|
|
||
| def translate_error(ex: Exception) -> DataConnectError: | ||
| """Map a transport-layer exception to the appropriate public ``DataConnectError`` subtype.""" | ||
|
|
||
|
slingampalli-mdsol marked this conversation as resolved.
|
||
| if isinstance(ex, DataConnectError): | ||
| return ex | ||
|
|
||
| if not isinstance(ex, TransportError): | ||
| return DataConnectError(error_code="SDK_ERROR", message=str(ex)) | ||
|
|
||
| error_details = [ | ||
| DataConnectErrorDetail(field=detail.field, message=detail.message, expected=detail.expected, extra=detail.extra) | ||
| for detail in ex.details or [] | ||
| ] | ||
|
|
||
| if isinstance(ex, TransportAuthenticationError): | ||
| return AuthenticationError( | ||
| error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details | ||
| ) | ||
|
|
||
| if isinstance(ex, TransportAuthorizationError): | ||
| return AuthorizationError( | ||
| error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details | ||
| ) | ||
|
|
||
| if isinstance(ex, TransportValidationError): | ||
| return ValidationError( | ||
| error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details | ||
| ) | ||
|
|
||
| if isinstance(ex, TransportNotFoundError): | ||
| return NotFoundError( | ||
| error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details | ||
| ) | ||
|
|
||
| if isinstance(ex, TransportServerError): | ||
| return ServerError(error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details) | ||
|
|
||
| # Non-specific transport error | ||
| return DataConnectError(error_code=ex.error_code, message=ex.message, timestamp=ex.timestamp, details=error_details) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.