private bool IsErrorHandled(WebServiceError error, Exception exception) { if (error == WebServiceError.InvalidCredentials || error == WebServiceError.SessionTokenExpired) { HandleLoginException(error); } else if (error == WebServiceError.Cancelled) { HandleExceptionByRetry(); } else if (error == WebServiceError.ServerNotFound) { HandleException(); } else if (exception != null) { HandleException(); } if (exception != null) { _analyticsService.LogError(exception); } return(exception != null); }
private static Exception CreateExceptionFromJson(Response response, WebServiceError webServiceError, string content) { if (webServiceError.Code == null || webServiceError.Error == null) { return(new HttpException( $"Response contains JSON but does not specify code or error keys: {content}", response.StatusCode, response.RequestUri)); } switch (webServiceError.Code) { case "IP_ADDRESS_NOT_FOUND": case "IP_ADDRESS_RESERVED": return(new AddressNotFoundException(webServiceError.Error)); case "ACCOUNT_ID_REQUIRED": case "ACCOUNT_ID_UNKNOWN": case "AUTHORIZATION_INVALID": case "LICENSE_KEY_REQUIRED": case "USER_ID_REQUIRED": case "USER_ID_UNKNOWN": return(new AuthenticationException(webServiceError.Error)); case "INSUFFICIENT_FUNDS": case "OUT_OF_QUERIES": return(new OutOfQueriesException(webServiceError.Error)); case "PERMISSION_REQUIRED": return(new PermissionRequiredException(webServiceError.Error)); default: return(new InvalidRequestException(webServiceError.Error, webServiceError.Code, response.RequestUri)); } }
private static void HandleErrorWithJsonBody(WebServiceError error, HttpResponseMessage response, string content) { if (error.Code == null || error.Error == null) { throw new HttpException( $"Error response contains JSON but it does not specify code or error keys: {content}", response.StatusCode, response.RequestMessage.RequestUri); } switch (error.Code) { case "ACCOUNT_ID_REQUIRED": case "AUTHORIZATION_INVALID": case "LICENSE_KEY_REQUIRED": case "USER_ID_REQUIRED": throw new AuthenticationException(error.Error); case "INSUFFICIENT_FUNDS": throw new InsufficientFundsException(error.Error); case "PERMISSION_REQUIRED": throw new PermissionRequiredException(error.Error); default: throw new InvalidRequestException(error.Error, error.Code, response.RequestMessage.RequestUri); } }
public async Task ShouldParseCancelledError() { var exception = new WebException("Test", WebExceptionStatus.RequestCanceled); WebServiceError error = await _deserializer.ParseWebServiceErrorAsync(exception); Assert.AreEqual(WebServiceError.Cancelled, error); }
private void HandleLoginException(WebServiceError error) { IsLoggedIn = false; // Missing test coverage. Set to false before true so UI updates. // How to test this? Or refactor out so not needed? IsLoggingIn = false; _sessionProvider.ClearSession(); CurrentError = error; IsLoggingIn = true; }
private static Exception CreateExceptionFromJson(Response response, WebServiceError webServiceError) { if (webServiceError.Code == null || webServiceError.Error == null) { var content = Encoding.UTF8.GetString(response.Content); return(new HttpException( $"Response contains JSON but does not specify code or error keys: {content}", response.StatusCode, response.RequestUri)); } return(webServiceError.Code switch { "IP_ADDRESS_NOT_FOUND" or "IP_ADDRESS_RESERVED" => new AddressNotFoundException(webServiceError.Error), "ACCOUNT_ID_REQUIRED" or "ACCOUNT_ID_UNKNOWN" or "AUTHORIZATION_INVALID" or "LICENSE_KEY_REQUIRED" => new AuthenticationException(webServiceError.Error), "INSUFFICIENT_FUNDS" or "OUT_OF_QUERIES" => new OutOfQueriesException(webServiceError.Error), "PERMISSION_REQUIRED" => new PermissionRequiredException(webServiceError.Error), _ => new InvalidRequestException(webServiceError.Error, webServiceError.Code, response.RequestUri), });
private static void HandleErrorWithJsonBody(WebServiceError webServiceError, IRestResponse response) { if (webServiceError.Code == null || webServiceError.Error == null) { throw new HttpException( "Response contains JSON but does not specify code or error keys: " + response.Content, response.StatusCode, response.ResponseUri); } if (webServiceError.Code == "IP_ADDRESS_NOT_FOUND" || webServiceError.Code == "IP_ADDRESS_RESERVED") { throw new AddressNotFoundException(webServiceError.Error); } else if (webServiceError.Code == "AUTHORIZATION_INVALID" || webServiceError.Code == "LICENSE_KEY_REQUIRED" || webServiceError.Code == "USER_ID_REQUIRED") { throw new AuthenticationException(webServiceError.Error); } else if (webServiceError.Code == "OUT_OF_QUERIES") { throw new OutOfQueriesException(webServiceError.Error); } throw new InvalidRequestException(webServiceError.Error, webServiceError.Code, response.ResponseUri); }
public GetThermostatStatusResult(WebServiceError error, Exception exception) { Error = error; Exception = exception; }
public WebServiceResult(WebServiceError error, Exception exception) { Error = error; Exception = exception; }
private void HandleLoginException(WebServiceError error) { _sessionProvider.ClearSession(); CurrentError = error; State = NestViewModelState.LoggingIn; }
private void ResetCurrentError() { CurrentError = WebServiceError.None; }
public GetStatusResult(WebServiceError error, Exception exception) { Error = error; Exception = exception; }
private bool IsErrorHandled(WebServiceError error, Exception exception) { if (error == WebServiceError.InvalidCredentials || error == WebServiceError.SessionTokenExpired) HandleLoginException(error); else if (error == WebServiceError.Cancelled) HandleExceptionByRetry(); else if (error == WebServiceError.ServerNotFound) HandleException(); else if (exception != null) HandleException(); if (exception != null) _analyticsService.LogError(exception); return exception != null; }