Skip to content

Commit a13cffa

Browse files
author
wallisyan
committed
fix serverExceptions
1 parent 6eaa5b4 commit a13cffa

File tree

16 files changed

+40
-187
lines changed

16 files changed

+40
-187
lines changed

aliyun-python-sdk-core/alibabacloud/endpoint/chained_endpoint_resolver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from alibabacloud.exceptions import ClientException
1919
from alibabacloud.endpoint import EndpointResolver
2020

21-
import aliyunsdkcore.acs_exception.error_code as error_code
2221
import aliyunsdkcore.acs_exception.error_msg as error_msg
2322

2423

aliyun-python-sdk-core/alibabacloud/exceptions.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
SDK_INVALID_REGION_ID = 'SDK.InvalidRegionId'
16-
SDK_SERVER_UNREACHABLE = 'SDK.ServerUnreachable'
17-
SDK_INVALID_REQUEST = 'SDK.InvalidRequest'
18-
SDK_MISSING_ENDPOINTS_FILER = 'SDK.MissingEndpointsFiler'
19-
SDK_UNKNOWN_SERVER_ERROR = 'SDK.UnknownServerError'
20-
SDK_INVALID_CREDENTIAL = 'SDK.InvalidCredential'
21-
SDK_INVALID_SESSION_EXPIRATION = 'SDK.InvalidSessionExpiration'
22-
SDK_GET_SESSION_CREDENTIAL_FAILED = 'SDK.GetSessionCredentialFailed'
23-
SDK_INVALID_PARAMS = 'SDK.InvalidParams'
24-
SDK_NOT_SUPPORT = 'SDK.NotSupport'
25-
SDK_ENDPOINT_RESOLVING_ERROR = 'SDK.EndpointResolvingError'
26-
SDK_ENDPOINT_TESTABILITY = 'SDK.EndpointTestability'
27-
SDK_HTTP_ERROR = 'SDK.HttpError'
28-
SDK_INVALID_PARAMETER = "SDK.InvalidParameter"
29-
3015

3116
class ClientException(Exception):
3217
"""client exception"""
@@ -49,19 +34,21 @@ def __str__(self):
4934

5035
class ServerException(Exception):
5136

52-
def __init__(self, error_code, error_message, endpoint=None,
53-
http_status=None, request_id=None, service_name= None):
37+
def __init__(self, error_code, error_message, endpoint=None, service_name=None,
38+
http_status=None, request_id=None):
5439
self.error_code = error_code
5540
self.error_message = error_message
5641
self.endpoint = endpoint
57-
self.http_status = http_status
58-
self.request_id = request_id
5942
# TODO service_name
6043
self.service_name = service_name
44+
self.http_status = http_status
45+
self.request_id = request_id
6146

6247
def __str__(self):
63-
return "HTTP Status: %s Error:%s %s RequestID: %s" % (
48+
return "HTTP Status: %s Product:%s Endpoint:%s Error:%s %s RequestID: %s" % (
6449
str(self.http_status),
50+
self.service_name,
51+
self.endpoint,
6552
self.error_code,
6653
self.error_message,
6754
self.request_id

aliyun-python-sdk-core/alibabacloud/handlers/server_error_handler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from alibabacloud.handlers import RequestHandler
1818
from alibabacloud.vendored.requests import codes
1919

20+
SDK_UNKNOWN_SERVER_ERROR = 'SDK.UnknownServerError'
21+
2022

2123
class ServerErrorHandler(RequestHandler):
2224

@@ -39,11 +41,6 @@ def handle_response(self, context):
3941

4042
server_error_code, server_error_message = self._parse_error_info_from_response_body(
4143
response.text)
42-
# with open('a', 'w') as f:
43-
# f.write(http_request.signature)
44-
# with open('b', 'w') as f:
45-
# f.write(server_error_message.split(':', 1)[1])
46-
4744
special_error_codes = ['IncompleteSignature', 'SignatureDoesNotMatch']
4845
if response.status_code == codes.BAD_REQUEST and \
4946
server_error_code in special_error_codes:
@@ -53,13 +50,13 @@ def handle_response(self, context):
5350
'Please check your AccessKeyId and AccessKeySecret.'
5451
from alibabacloud.exceptions import ServerException
5552
exception = ServerException(server_error_code, server_error_message,
56-
context.endpoint, response.status_code, request_id)
53+
context.endpoint, context.client.product_code,
54+
response.status_code, request_id)
5755
context.exception = exception
5856

5957
@staticmethod
6058
def _parse_error_info_from_response_body(response_body):
61-
from aliyunsdkcore.acs_exception import error_code
62-
error_code_to_return = error_code.SDK_UNKNOWN_SERVER_ERROR
59+
error_code_to_return = SDK_UNKNOWN_SERVER_ERROR
6360
# TODO handle if response_body is too big
6461
error_message_to_return = "ServerResponseBody: " + str(response_body)
6562
try:

aliyun-python-sdk-core/alibabacloud/retry/retry_condition.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from alibabacloud.utils.load_json_from_data_dir import _load_json_from_data_dir
1919
import alibabacloud.utils.validation as validation
2020
from alibabacloud.exceptions import ServerException, ClientException
21-
import aliyunsdkcore.acs_exception.error_code as error_code
2221

2322
logger = logging.getLogger(__name__)
2423

aliyun-python-sdk-core/alibabacloud/utils/validation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
from alibabacloud.exceptions import ClientException
1616

17-
import aliyunsdkcore.acs_exception.error_code as error_code
18-
1917

2018
def assert_integer_positive(integer, name):
2119
if isinstance(integer, int) and integer > 0:

aliyun-python-sdk-core/aliyunsdkcore/acs_exception/error_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
SDK_ENDPOINT_RESOLVING_ERROR = 'SDK.EndpointResolvingError'
3737
SDK_ENDPOINT_TESTABILITY = 'SDK.EndpointTestability'
3838
SDK_HTTP_ERROR = 'SDK.HttpError'
39-
SDK_INVALID_PARAMETER = "SDK.InvalidParameter"
39+
SDK_INVALID_PARAMETER = "SDK.InvalidParameter"

aliyun-python-sdk-core/aliyunsdkcore/acs_exception/error_msg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747

4848

4949
def get_msg(code):
50-
return __dict.get(code)
50+
return __dict.get(code)

aliyun-python-sdk-core/aliyunsdkcore/acs_exception/error_type.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

aliyun-python-sdk-core/aliyunsdkcore/acs_exception/exceptions.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

aliyun-python-sdk-core/aliyunsdkcore/auth/signers/signer_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import logging
44
import os
5-
from aliyunsdkcore.acs_exception import error_msg
6-
from aliyunsdkcore.acs_exception import error_code
7-
from aliyunsdkcore.acs_exception import exceptions
5+
# from aliyunsdkcore.acs_exception import error_msg
6+
# from aliyunsdkcore.acs_exception import error_code
7+
# from aliyunsdkcore.acs_exception import exceptions
8+
from alibabacloud.exceptions import ClientException
89
from aliyunsdkcore.auth import credentials
910
from aliyunsdkcore.auth.signers import access_key_signer
1011
from aliyunsdkcore.auth.signers import sts_token_signer
@@ -46,5 +47,4 @@ def get_signer(cred, region_id, do_action_api, debug=False):
4647
cred['session_period'])
4748
return rsa_key_pair_signer.RsaKeyPairSigner(rsa_key_pair_credential, region_id, debug)
4849
else:
49-
raise exceptions.ClientException(error_code.SDK_INVALID_CREDENTIAL,
50-
error_msg.get_msg('SDK_INVALID_CREDENTIAL'))
50+
raise ClientException(error_msg.get_msg('SDK_INVALID_CREDENTIAL'))

0 commit comments

Comments
 (0)