internal InvalidCredentialsException(RecurlyError[] errors) : base("The API credentials for Recurly are invalid. Please check the credentials and try again.", errors) { }
internal RecurlyException(string message, RecurlyError[] errors) : base(message) { Errors = errors; }
public static HttpStatusCode PerformRequest(HttpRequestMethod method, string urlPath, WriteXmlDelegate writeXmlDelegate, ReadXmlDelegate readXmlDelegate) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ServerUrl(Environment) + urlPath); request.Accept = "application/xml"; // Tells the server to return XML instead of HTML request.ContentType = "application/xml; charset=utf-8"; // The request is an XML document request.SendChunked = false; // Send it all as one request request.UserAgent = UserAgent; request.Headers.Add(HttpRequestHeader.Authorization, AuthorizationHeaderValue); request.Method = method.ToString().ToUpper(); System.Diagnostics.Debug.WriteLine(String.Format("Recurly: Requesting {0} {1}", request.Method, request.RequestUri.ToString())); if ((method == HttpRequestMethod.Post || method == HttpRequestMethod.Put) && (writeXmlDelegate != null)) { // 60 second timeout -- some payment gateways (e.g. PayPal) can take a while to respond request.Timeout = 60000; // Write POST/PUT body using (Stream requestStream = request.GetRequestStream()) WritePostParameters(requestStream, writeXmlDelegate); } try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) return(ReadWebResponse(response, readXmlDelegate)); } catch (WebException ex) { if (ex.Response != null) { HttpWebResponse response = (HttpWebResponse)ex.Response; HttpStatusCode statusCode = response.StatusCode; RecurlyError[] errors; System.Diagnostics.Debug.WriteLine(String.Format("Recurly Library Received: {0} - {1}", (int)statusCode, statusCode.ToString())); switch (response.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Accepted: case HttpStatusCode.Created: case HttpStatusCode.NoContent: return(ReadWebResponse(response, readXmlDelegate)); case HttpStatusCode.NotFound: errors = RecurlyError.ReadResponseAndParseErrors(response); if (errors.Length >= 0) { throw new NotFoundException(errors[0].Message, errors); } else { throw new NotFoundException("The requested object was not found.", errors); } case HttpStatusCode.Unauthorized: case HttpStatusCode.Forbidden: errors = RecurlyError.ReadResponseAndParseErrors(response); throw new InvalidCredentialsException(errors); case HttpStatusCode.PreconditionFailed: errors = RecurlyError.ReadResponseAndParseErrors(response); throw new ValidationException(errors); case HttpStatusCode.ServiceUnavailable: throw new TemporarilyUnavailableException(); case HttpStatusCode.InternalServerError: errors = RecurlyError.ReadResponseAndParseErrors(response); throw new RecurlyServerException(errors); } if ((int)statusCode == ValidationException.HttpStatusCode) // Unprocessable Entity { errors = RecurlyError.ReadResponseAndParseErrors(response); throw new ValidationException(errors); } } throw; } }
internal RecurlyException(RecurlyError[] errors) { Errors = errors; }
internal ValidationException(string message, RecurlyError[] errors) : base(message, errors) { }
internal ValidationException(RecurlyError[] errors) : base("The information being saved is not valid.", errors) { }
internal NotFoundException(string message, RecurlyError[] errors) : base(message, errors) { }
public RecurlyErrorException(RecurlyError error) : base() { this.Error = error; }