private static void ThrowIfNotSuccessful(WebApiResponse response) { if (response.Successful) { return; } if (response.ErrorException != null) { throw new CommandLineException(CommandLineErrorCode.WebApiUnreachable, response.ErrorException); } if (response is IResponseWithErrorData <ApiError> r && r.ErrorContent != null) { throw new CommandLineException(CommandLineErrorCode.WebApiCallFriendlyError, r.ErrorContent.Message); } throw new CommandLineException( CommandLineErrorCode.WebApiCallGenericError, string.Format(CommandLineErrorCode.WebApiCallGenericError.GetDefaultMessage(), response.ErrorStatusCode)); }
private static WebApiResponse WrapRestResponse(RestClient client, RestRequest request, IRestResponse response) { WebApiResponse result = new WebApiResponse(); Uri requestUri = client.BuildUri(request); if (response.IsSuccessful) { result.Successful = true; } else if (response.ErrorException != null) { Log.Error("Network/framework exception on REST request '{0}'", requestUri); Log.Ex(response.ErrorException); result.ErrorException = response.ErrorException; } else { Log.Error("Error {1} ({2}) on REST request '{0}'", requestUri, (int)response.StatusCode, response.StatusDescription); result.ErrorStatusCode = response.StatusCode; } return(result); }