/// <summary> /// Imprime los mensajes de error retornados por el servicio /// </summary> /// <param name="e"></param> private static void PrintErrors(PayPhoneWebException e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{e.StatusCode} - {e.Error.Message} "); if (e.Error.Errors != null && e.Error.Errors.Count > 0) { foreach (var item in e.Error.Errors) { if (item.ErrorDescriptions == null || item.ErrorDescriptions.Length <= 0) { Console.WriteLine($"{item.Message}"); } else { Console.WriteLine($"({item.Message} - {string.Join(";", item.ErrorDescriptions)})"); } } } Console.ResetColor(); }
/// <summary> /// Update the actual token for new one /// Validate if exception receive is of Unauthorized type /// </summary> /// <param name="e">Exception returned by PayPhone</param> /// <returns></returns> private static bool RefreshToken(PayPhoneWebException e) { try { if (unauthorizedCount == 0) { //Check status code oofthe response if (e.StatusCode.Equals(HttpStatusCode.Unauthorized.ToString())) { //If status code is Unauthorized get a new token and replace var token = connection.GetToken(Configurations.Ruc); Configurations.Token = token.Access_Token; unauthorizedCount++; return(true); } } return(false); } catch (PayPhoneWebException exc) { //Remember all call in PayPHone return an exception //Capture the exception and observe what happens Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"401 - Unathorize {exc.Message}"); Console.ResetColor(); return(false); } catch (Exception exc) { //Always is recomended have generic exception for possibles errors generate from your code Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception " + exc.Message); Console.ResetColor(); return(false); } }