Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions aliyun-net-sdk-core.Tests/Units/DefaultAcsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void DoAction2()

var result = instance.DoAction(request, true, 1, "cn-hangzhou", credentials, signer, FormatType.JSON, null);

Assert.Equal(result,response);
Assert.Equal(result, response);
}

[Fact]
Expand Down Expand Up @@ -445,7 +445,7 @@ public void GetAcsResponseWhenStatusIsNotSuccess()
var ex = Record.Exception(testCode400);
Assert.NotNull(ex);
Assert.IsType<ClientException>(ex);
Assert.Equal("ThisIsCode : ThisIsMessage", ex.Message);
Assert.Contains("ThisIsCode : ThisIsMessage", ex.Message);

// 502 Error
instance = MockDefaultAcsClient(502);
Expand All @@ -456,7 +456,7 @@ public void GetAcsResponseWhenStatusIsNotSuccess()
ex = Record.Exception(testCode400);
Assert.NotNull(ex);
Assert.IsType<ServerException>(ex);
Assert.Equal("ThisIsCode : ThisIsMessage, the request url is empty, the RequestId is ThisIsRequestId.", ex.Message);
Assert.Contains("ThisIsCode : ThisIsMessage, the request url is empty, the RequestId is ThisIsRequestId.", ex.Message);
}

[Fact]
Expand Down Expand Up @@ -852,7 +852,7 @@ public void TestIncompleteSignature()
var result = instance.GetAcsResponse(request, "cn-hangzhou", credentials);
});

Assert.Equal(
Assert.Contains(
"IncompleteSignature : The request signature does not conform to Aliyun standards. server string to sign is:Error Signature",
signatureException.Message);

Expand All @@ -864,7 +864,7 @@ public void TestIncompleteSignature()
var result = instance.GetAcsResponse(request, "cn-hangzhou", credentials);
});

Assert.Equal("SDK.InvalidAccessKeySecret : Specified Access Key Secret is not valid.",
Assert.Contains("SDK.InvalidAccessKeySecret : Specified Access Key Secret is not valid.",
invalidException.Message);
}

Expand All @@ -882,7 +882,7 @@ public void TestSignatureDoesNotMatch()
var result = instance.GetAcsResponse(request, "cn-hangzhou", credentials);
});

Assert.Equal(
Assert.Contains(
"SignatureDoesNotMatch : signature does not conform to standards. server string to sign is:Error Signature",
signatureException.Message);

Expand All @@ -894,7 +894,7 @@ public void TestSignatureDoesNotMatch()
var result = instance.GetAcsResponse(request, "cn-hangzhou", credentials);
});

Assert.Equal("SDK.InvalidAccessKeySecret : Specified Access Key Secret is not valid.",
Assert.Contains("SDK.InvalidAccessKeySecret : Specified Access Key Secret is not valid.",
invalidException.Message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Instance1()
var exception = new ClientException("200", "message", "requestId");
Assert.Equal("200", exception.ErrorCode);
Assert.Equal("message", exception.ErrorMessage);
Assert.Null(exception.RequestId);
Assert.Equal("requestId", exception.RequestId);
}

[Fact]
Expand Down
9 changes: 7 additions & 2 deletions aliyun-net-sdk-core/Exceptions/ClientException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -23,8 +23,13 @@ namespace Aliyun.Acs.Core.Exceptions
{
public class ClientException : Exception
{
public ClientException(string errCode, string errMsg, string requestId) : this(errCode, errMsg)
public ClientException(string errCode, string errMsg, string requestId) : base(
string.Format("{0} : {1} + [ RequestId : {2} ]", errCode, errMsg, requestId))
{
ErrorType = ErrorType.Client;
ErrorMessage = errMsg;
RequestId = requestId;
ErrorCode = errCode;
}

public ClientException(string errCode, string errMsg) : base(errCode + " : " + errMsg)
Expand Down
4 changes: 2 additions & 2 deletions aliyun-net-sdk-core/Exceptions/ServerException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -22,7 +22,7 @@ namespace Aliyun.Acs.Core.Exceptions
public class ServerException : ClientException
{
public ServerException(string errorCode, string errorMessage, string requestId) :
this(errorCode, errorMessage)
base(errorCode, errorMessage, requestId)
{
RequestId = requestId;
}
Expand Down
2 changes: 1 addition & 1 deletion aliyun-sdk-feature-test/Credential/CredentialsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void STSAssumeRoleCredentialWithPolicyTest()

var exception = Assert.Throws<ClientException>(() => { response = client.GetAcsResponse(request); });

Assert.Equal(
Assert.Contains(
"Forbidden.RAM : User not authorized to operate on the specified resource, or this API doesn't support RAM.",
exception.Message);
}
Expand Down