public static async Task <T> RunAsync <T>(Task <T> task, bool logNotFoundException = true) { try { await task; return(task.Result); } catch (Exception ex) { if (!logNotFoundException && ex is RestServiceRequestException) { RestServiceRequestException restEx = (RestServiceRequestException)ex; if (restEx.StatusCode == HttpStatusCode.NotFound) { return(default(T)); } } Logger.Log(ex); } return(default(T)); }
public async Task <string> ProcessStringResponse(HttpResponseMessage response) { if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created) { string result = await response.Content.ReadAsStringAsync(); if (this.OnSuccessResponseReceived != null) { this.OnSuccessResponseReceived(this, result); } return(result); } else { RestServiceRequestException ex = new RestServiceRequestException(response); if (this.OnFailureResponseReceived != null) { this.OnFailureResponseReceived(this, ex); } throw ex; } }
private void RestAPIServices_OnFailureResponseReceived(object sender, RestServiceRequestException e) { Util.Logger.Log(string.Format("Rest API Failure Response: {0}", e.ToString())); }