/// <summary> /// Extracts an <see cref="ErrorResult"/> from the provided <paramref name="exception"/> /// </summary> /// <param name="exception">API exception response</param> /// <param name="settings">Serializer settings for parsing the exception message</param> /// <returns>A new <see cref="ErrorResult"/> representing the specified <paramref name="exception"/></returns> public static ErrorResult GetErrorResult(this ApiHandledException exception, JsonSerializerSettings settings) { var errorResult = new ErrorResult() { Errors = new List <string>() { exception.Message } }; exception.ApiException.Match(arg => { errorResult = arg.GetErrorResult(settings); }, () => { }); return(errorResult); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (_connectivity.IsConnected) { return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false)); } var errorResult = new ErrorResult() { ErrorMessage = ErrorMessages.NoNetWorkError }; var content = new StringContent(JsonConvert.SerializeObject(errorResult)); var response = new HttpResponseMessage(HttpStatusCode.RequestTimeout) { Content = content }; return(await Task.FromResult(response).ConfigureAwait(false)); }