コード例 #1
0
        /// <summary>
        /// Parses the <paramref name="content"/> to an Gmail API error response.
        /// </summary>
        /// <param name="statusCode"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static GmailException Parse(HttpStatusCode statusCode, string content)
        {
            JObject jObject      = JObject.Parse(content);
            JToken  errorContent = jObject.SelectToken("error", false);

            // Return just the StatusCode and content in case the response is not an Gmail API error
            if (errorContent == null || !jObject.IsValid(JsonSchema))
            {
                return(new GmailException(statusCode, content));
            }

            GmailErrorResponse errorResponse = errorContent.ToObject <GmailErrorResponse>();

            return(new GmailException(errorResponse));
        }
コード例 #2
0
 internal GmailException(GmailErrorResponse errorResponse)
     : this(errorResponse, null)
 {
 }
コード例 #3
0
 private static string ConstructMessage(GmailErrorResponse errorResponse)
 {
     return(string.Concat(errorResponse.Code, ": ", errorResponse.Message));
 }
コード例 #4
0
 internal GmailException(GmailErrorResponse errorResponse, Exception innerException)
     : base(ConstructMessage(errorResponse), innerException)
 {
     StatusCode = (HttpStatusCode)errorResponse.Code;
     Errors     = errorResponse.Errors;
 }