public static async Task <T> SendRequestAsync <T>(this Task <T> asyncRequest) { try { return(await asyncRequest.ConfigureAwait(false)); } catch (FlurlHttpException ex) { CouchError couchError = await ex.GetResponseJsonAsync <CouchError>().ConfigureAwait(false); if (couchError == null) { couchError = new CouchError(); } switch (ex.Call.HttpStatus) { case HttpStatusCode.Conflict: throw new CouchConflictException(couchError, ex); case HttpStatusCode.NotFound: throw new CouchNotFoundException(couchError, ex); case HttpStatusCode.BadRequest when couchError.Error == "no_usable_index": throw new CouchNoIndexException(couchError, ex); default: throw new CouchException(couchError, ex); } } }
public static void HandleNoneOKResponse(RestResponse Response, IJSONHelper JsonHelper) { CouchError error = null; if ((Response.ResponseCode & (HttpStatusCode.InternalServerError | HttpStatusCode.NotFound | HttpStatusCode.Unauthorized)) > 0) { error = JsonHelper.FromJSON <CouchError>(Response.Content); if (error != null) { error.HTTPCode = (int)Response.ResponseCode; } else { throw new PillowException($"Error in Couch response, unable to parse error info. Raw:{Response.Content}"); } } else { error = new CouchError() { Error = "Generic", HTTPCode = (int)Response.ResponseCode, Reason = "Error, see status code" }; } throw new CouchException(error); }
public CouchException(CouchError Error) : base(message: Error?.ToString()) { this.Error = Error; if (Error != null) { Console.WriteLine(this.ToString()); } }
private static string ProccessResponse(string responseJsonString) { var error = new CouchError(new NewtonsoftSerializer(), new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new JsonContent(responseJsonString) }); return(error.ToString()); }
public static async Task <TResult> SendRequestAsync <TResult>(this Task <TResult> asyncRequest) { try { return(await asyncRequest.ConfigureAwait(false)); } catch (FlurlHttpException ex) { CouchError couchError = await ex.GetResponseJsonAsync <CouchError>().ConfigureAwait(false) ?? new CouchError(); throw (HttpStatusCode?)ex.StatusCode switch { HttpStatusCode.Conflict => new CouchConflictException(couchError, ex), HttpStatusCode.NotFound => new CouchNotFoundException(couchError, ex), HttpStatusCode.BadRequest when couchError.Error == "no_usable_index" => new CouchNoIndexException( couchError, ex), _ => new CouchException(couchError, ex) }; } } }
internal CouchException(CouchError couchError, Exception innerException) : this(couchError?.Error, couchError?.Reason, innerException) { }
internal CouchNotFoundException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }
internal CouchNoIndexException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }
internal CouchConflictException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }