-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parameter assignment in error handling function (#1616)
- Loading branch information
1 parent
3e8b7b0
commit 02d45de
Showing
7 changed files
with
145 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
36 changes: 36 additions & 0 deletions
36
stix_shifter_modules/crowdstrike/stix_transmission/error_mapper.py
This file contains 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,36 @@ | ||
from stix_shifter_utils.utils.error_mapper_base import ErrorMapperBase | ||
from stix_shifter_utils.utils.error_response import ErrorCode | ||
from stix_shifter_utils.utils import logger | ||
|
||
error_mapping = { | ||
"ConnectionError": ErrorCode.TRANSMISSION_REMOTE_SYSTEM_IS_UNAVAILABLE, | ||
"AuthenticationError": ErrorCode.TRANSMISSION_AUTH_CREDENTIALS, | ||
"ValidationError": ErrorCode.TRANSMISSION_QUERY_LOGICAL_ERROR, | ||
"AttributeError": ErrorCode.TRANSMISSION_INVALID_PARAMETER, | ||
} | ||
|
||
|
||
class ErrorMapper: | ||
""" | ||
Set Error Code | ||
""" | ||
logger = logger.set_logger(__name__) | ||
DEFAULT_ERROR = ErrorCode.TRANSMISSION_MODULE_DEFAULT_ERROR | ||
|
||
@staticmethod | ||
def set_error_code(json_data, return_obj, connector=None): | ||
err_type = None | ||
try: | ||
err_type = json_data['type'] | ||
except KeyError: | ||
pass | ||
|
||
error_type = ErrorMapper.DEFAULT_ERROR | ||
|
||
if err_type in error_mapping: | ||
error_type = error_mapping.get(err_type) | ||
|
||
if error_type == ErrorMapper.DEFAULT_ERROR: | ||
ErrorMapper.logger.error("failed to map: %s", str(json_data)) | ||
|
||
ErrorMapperBase.set_error_code(return_obj, error_type, connector=connector) |
This file contains 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 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