using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Text; using COSXML.Model.Tag; namespace COSXML.CosException { /// /// 服务器异常,通常是一个非正确的服务器响应,例如权限错误、服务不可用等。 /// /// [Serializable] public class CosServerException : System.ApplicationException { /// /// http status code /// public int statusCode; /// /// http status message /// public string statusMessage; /// /// cos server error code /// public string errorCode; /// /// cos server error message /// public string errorMessage; /// /// cos server requestId for tracking error /// public string requestId; /// /// cos server trace id /// public string traceId; /// /// cos server resuorce /// public string resource; public CosServerException(int statusCode, string statusMessage, CosServerError serverError) : this(statusCode, statusMessage) { if (serverError != null) { this.resource = serverError.resource; this.errorCode = serverError.code; this.errorMessage = serverError.message; this.requestId = serverError.requestId; this.traceId = serverError.traceId; } } public CosServerException(int statusCode, string statusMessage) : base("CosServerException: {" + statusCode + "} - {" + statusMessage + "}") { this.statusCode = statusCode; this.statusMessage = statusMessage; } public void SetCosServerError(CosServerError serverError) { if (serverError != null) { this.resource = serverError.resource; this.errorCode = serverError.code; this.errorMessage = serverError.message; this.requestId = serverError.requestId; this.traceId = serverError.traceId; } } public string GetInfo() { StringBuilder builder = new StringBuilder(); builder.Append("(") .Append("statusCode = ").Append(statusCode).Append(", statusMessage = ").Append(statusMessage) .Append(", errorCode = ").Append(errorCode).Append(", errorMessage = ").Append(errorMessage) .Append(", requestId = ").Append(requestId).Append(", traceId = ").Append(traceId) .Append(", resouce = ").Append(resource) .Append(")"); return builder.ToString(); } } }