private void HandleError(IVndbError error) { if (error is MissingError missing) { Console.WriteLine($"A Missing Error occured, the field \"{missing.Field}\" was missing."); } else if (error is BadArgumentError badArg) { Console.WriteLine($"A BadArgument Error occured, the field \"{badArg.Field}\" is invalid."); } else if (error is ThrottledError throttled) { var minSeconds = (throttled.MinimumWait - DateTime.Now).TotalSeconds; // Not sure if this is correct var fullSeconds = (throttled.FullWait - DateTime.Now).TotalSeconds; // Not sure if this is correct Console.WriteLine( $"A Throttled Error occured, you need to wait at minimum \"{minSeconds}\" seconds, " + $"and preferably \"{fullSeconds}\" before issuing commands."); } else if (error is GetInfoError getInfo) { Console.WriteLine($"A GetInfo Error occured, the flag \"{getInfo.Flag}\" is not valid on the issued command."); } else if (error is InvalidFilterError invalidFilter) { Console.WriteLine( $"A InvalidFilter Error occured, the filter combination of \"{invalidFilter.Field}\", " + $"\"{invalidFilter.Operator}\", \"{invalidFilter.Value}\" is not a valid combination."); } else { Console.WriteLine($"A {error.Type} Error occured."); } Console.WriteLine($"Message: {error.Message}"); }
/// <summary> /// Handles Vndb API errors, writes the error message to a file, then resets the statusbar /// </summary> /// <param name="error">Vndb Error</param> public static void HandleErrors(IVndbError error) { if (error == null) { return; } switch (error) { case MissingError missing: Debug.WriteLine($"A Missing Error occurred, the field {missing.Field} was missing."); App.Logger.Warning($"A Missing Error occurred, the field {missing.Field} was missing."); break; case BadArgumentError badArg: Debug.WriteLine($"A BadArgument Error occurred, the field {badArg.Field} is invalid."); App.Logger.Warning($"A BadArgument Error occurred, the field {badArg.Field} is invalid."); break; case ThrottledError throttled: Debug.WriteLine($"A Throttled Error occurred, use the ThrottledWaitAsync() method to wait for the {throttled.MinimumWait.Second} seconds needed."); App.Logger.Warning($"A Throttled Error occurred, use the ThrottledWaitAsync() method to wait for the {throttled.MinimumWait.Second} seconds needed."); break; case GetInfoError getInfo: Debug.WriteLine($"A GetInfo Error occurred, the flag {getInfo.Flag} is not valid on the issued command."); App.Logger.Warning($"A GetInfo Error occurred, the flag {getInfo.Flag} is not valid on the issued command."); break; case InvalidFilterError invalidFilter: Debug.WriteLine($"A InvalidFilter Error occurred, the filter combination of {invalidFilter.Field}, {invalidFilter.Operator}, {invalidFilter.Value} is not a valid combination."); App.Logger.Warning($"A InvalidFilter Error occurred, the filter combination of {invalidFilter.Field}, {invalidFilter.Operator}, {invalidFilter.Value} is not a valid combination."); break; case BadAuthenticationError badAuthentication: Debug.WriteLine($"A BadAuthenticationError occurred. This is caused by an incorrect username or password.\nMessage: {badAuthentication.Message}"); App.Logger.Warning($"A BadAuthenticationError occurred. This is caused by an incorrect username or password.\nMessage: {badAuthentication.Message}"); break; default: Debug.WriteLine($"A {error.Type} Error occurred.\nMessage: {error.Message}"); App.Logger.Warning($"A {error.Type} Error occurred.\nMessage: {error.Message}"); break; } StatusBarViewModel.ResetValues(); }
public static async void HandleErrors(IVndbError error, int counter) { if (error is MissingError missing) { Debug.WriteLine($"A Missing Error occured, the field \"{missing.Field}\" was missing."); } else if (error is BadArgumentError badArg) { Debug.WriteLine($"A BadArgument Error occured, the field \"{badArg.Field}\" is invalid."); } else if (error is ThrottledError throttled) { try { if (throttled.MinimumWait.Year < 2000) { return; } Debug.WriteLine("minsec: " + (throttled.MinimumWait - DateTime.Now).TotalSeconds); Debug.WriteLine("maxsec: " + (throttled.FullWait - DateTime.Now).TotalSeconds); var minSeconds = TimeSpan.FromSeconds((throttled.MinimumWait - DateTime.Now).TotalSeconds); // Not sure if this is correct var fullSeconds = TimeSpan.FromSeconds((throttled.FullWait - DateTime.Now).TotalSeconds); // Not sure if this is correct Debug.WriteLine( $"A Throttled Error occured, you need to wait at minimum \"{minSeconds}\" seconds, " + $"and preferably \"{fullSeconds}\" before issuing commands."); TimeSpan timeSpan; //double sleepTime = 0; //set seconds to sleep if (counter == 0) { timeSpan = TimeSpan.FromSeconds(minSeconds.TotalSeconds); } else if (counter >= 1) { timeSpan = TimeSpan.FromSeconds(minSeconds.TotalSeconds * counter); } else { timeSpan = TimeSpan.FromSeconds(5); } //make sure sleepTime doesn't go above the maximum amount of seconds needed if (timeSpan > fullSeconds) { timeSpan = TimeSpan.FromSeconds(fullSeconds.TotalSeconds); } if (timeSpan >= new TimeSpan(0, 0, 0, 0, 0)) { Debug.WriteLine($"Please wait {timeSpan.TotalMinutes} minutes and {timeSpan.TotalSeconds} seconds"); Thread.Sleep(timeSpan); } } catch (Exception ex) { Globals.Logger.Error(ex); throw; } } else if (error is GetInfoError getInfo) { Debug.WriteLine($"A GetInfo Error occured, the flag \"{getInfo.Flag}\" is not valid on the issued command."); } else if (error is InvalidFilterError invalidFilter) { Debug.WriteLine( $"A InvalidFilter Error occured, the filter combination of \"{invalidFilter.Field}\", " + $"\"{invalidFilter.Operator}\", \"{invalidFilter.Value}\" is not a valid combination."); } else if (error is BadAuthenticationError badAuthentication) { Debug.WriteLine( $"A BadAuthenticationError occured. This is caused by an incorrect username or pasword.\n" + $"Message: {badAuthentication.Message}"); } else { Debug.WriteLine($"A {error.Type} Error occured."); } Debug.WriteLine($"Message: {error.Message}"); }