/// <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)); }
internal GmailException(GmailErrorResponse errorResponse) : this(errorResponse, null) { }
private static string ConstructMessage(GmailErrorResponse errorResponse) { return(string.Concat(errorResponse.Code, ": ", errorResponse.Message)); }
internal GmailException(GmailErrorResponse errorResponse, Exception innerException) : base(ConstructMessage(errorResponse), innerException) { StatusCode = (HttpStatusCode)errorResponse.Code; Errors = errorResponse.Errors; }