private static void MapAndThrowException(Exception exception, FutError futError) { // TODO: Should extract this to a separate class and keep them in a Dictionary<FutErrorCode, Func<FutError, Exception, FutErrorException>> switch (futError.Code) { case FutErrorCode.ExpiredSession: throw new ExpiredSessionException(futError, exception); case FutErrorCode.NotFound: throw new NotFoundException(futError, exception); case FutErrorCode.Conflict: throw new ConflictException(futError, exception); case FutErrorCode.BadRequest: throw new BadRequestException(futError, exception); case FutErrorCode.PermissionDenied: throw new PermissionDeniedException(futError, exception); case FutErrorCode.NotEnoughCredit: throw new NotEnoughCreditException(futError, exception); case FutErrorCode.NoSuchTradeExists: throw new NoSuchTradeExistsException(futError, exception); case FutErrorCode.InternalServerError: throw new InternalServerException(futError, exception); case FutErrorCode.ServiceUnavailable: throw new ServiceUnavailableException(futError, exception); case FutErrorCode.InvalidDeck: throw new InvalidDeckException(futError, exception); case FutErrorCode.DestinationFull: throw new DestinationFullException(futError, exception); case FutErrorCode.CaptchaTriggered: throw new CaptchaTriggeredException(futError, exception); case FutErrorCode.PurchasedItemsFull: throw new PurchasedItemsFullException(futError, exception); default: var newException = new FutErrorException(futError, exception); throw new FutException(string.Format("Unknown EA error, please report on GitHub - {0}", newException.Message), newException); } }
private static void MapAndThrowException(Exception exception, FutError futError) { switch (futError.Code) { case FutErrorCode.ExpiredSession: throw new ExpiredSessionException(futError, exception); case FutErrorCode.NotFound: throw new NotFoundException(futError, exception); case FutErrorCode.Conflict: throw new ConflictException(futError, exception); case FutErrorCode.BadRequest: throw new BadRequestException(futError, exception); case FutErrorCode.PermissionDenied: throw new PermissionDeniedException(futError, exception); case FutErrorCode.NotEnoughCredit: throw new NotEnoughCreditException(futError, exception); case FutErrorCode.NoSuchTradeExists: throw new NoSuchTradeExistsException(futError, exception); case FutErrorCode.InternalServerError: throw new InternalServerException(futError, exception); case FutErrorCode.ServiceUnavailable: throw new ServiceUnavailableException(futError, exception); case FutErrorCode.InvalidDeck: throw new InvalidDeckException(futError, exception); case FutErrorCode.DestinationFull: throw new DestinationFullException(futError, exception); default: var newException = new FutErrorException(futError, exception); throw new FutException(string.Format("Unknown EA error, please report on GitHub - {0}", newException.Message), newException); } }
private static void MapAndThrowException <T>(Exception exception, FutError futError) where T : class { switch (futError.Code) { case FutErrorCode.ExpiredSession: futError.Reason = $"Session expired - You need to relogin"; throw new ExpiredSessionException(futError, exception); case FutErrorCode.NotFound: futError.Reason = $"Destination not found (404)"; throw new NotFoundException(futError, exception); case FutErrorCode.Conflict: if (Activator.CreateInstance(typeof(T)) is ListAuctionResponse) { futError.Reason = $"Conflict - Please check the EA pricerange"; throw new WrongPriceRangeException(futError, exception); } else { futError.Reason = $"Conflict"; throw new ConflictException(futError, exception); } case FutErrorCode.BadRequest: futError.Reason = $"Bad Request"; throw new BadRequestException(futError, exception); case FutErrorCode.PermissionDenied: futError.Reason = $"Permission Denied - You need to find the auction before bidding / Auction not existing"; throw new PermissionDeniedException(futError, exception); case FutErrorCode.NotEnoughCredit: futError.Reason = $"Not enough coins"; throw new NotEnoughCreditException(futError, exception); case FutErrorCode.NoSuchTradeExists: futError.Reason = $"Trade not found"; throw new NoSuchTradeExistsException(futError, exception); case FutErrorCode.InternalServerError: if (Activator.CreateInstance(typeof(T)) is AuctionResponse) { futError.Reason = $"Temporary Transfermarket BAN detected"; throw new TemporaryBanException(futError, exception); } else { futError.Reason = $"Internal Server Error - FUT unavailable"; throw new InternalServerException(futError, exception); } case FutErrorCode.ServiceUnavailable: futError.Reason = $"Service Unavailable"; throw new ServiceUnavailableException(futError, exception); case FutErrorCode.InvalidDeck: futError.Reason = $"Invalid Deck"; throw new InvalidDeckException(futError, exception); case FutErrorCode.DestinationFull: futError.Reason = $"Destination Pile (Watchlist / Transferlist) is full"; throw new DestinationFullException(futError, exception); case FutErrorCode.BadGateway: futError.Reason = $"Bad Gateway - Please try to relogin"; throw new BadGatewayException(futError, exception); case FutErrorCode.InvalidCookie: futError.Reason = $"Invalid Cookie - Please try to relogin"; throw new InvalidCookieException(futError, exception); case FutErrorCode.InvalidTransaction: futError.Reason = $"Invalid Transaction (i.e. if you try to list an aution which is still active)"; throw new InvalidTransactionException(futError, exception); case FutErrorCode.PurchasedItemsFull: futError.Reason = $"Purchased Items Pile is full - You need to assign them to club or transferlist"; throw new PurchasedItemsFullException(futError, exception); case FutErrorCode.NoRemainingAuthenticationAttemptsAccountLocked: futError.Reason = $"Account locked - You need to set the security question in a validated console"; throw new AccountLockedException(futError, exception); case FutErrorCode.TooManyRequests: futError.Reason = $"Temporary BAN detected"; throw new TemporaryBanException(futError, exception); case FutErrorCode.Unknown_HTTP_512: futError.Reason = $"Temporary BAN detected"; throw new TemporaryBanException(futError, exception); case FutErrorCode.Unknown_HTTP_521: futError.Reason = $"Temporary BAN detected"; throw new TemporaryBanException(futError, exception); case FutErrorCode.UpgradeRequired: futError.Reason = $"Temporary BAN detected"; throw new TemporaryBanException(futError, exception); case FutErrorCode.ServiceDisabled: futError.Reason = $"FUT WebApp / CompanionApp disabled by EA"; throw new ServiceDisabledException(futError, exception); case FutErrorCode.TransfermarketBlocked: futError.Reason = $"Transfermarket blocked by EA"; throw new TransfermarketBlockedException(futError, exception); case FutErrorCode.CaptchaTriggered: futError.Reason = "Captcha triggered"; throw new CaptchaTriggeredException(futError, exception); default: var newException = new FutErrorException(futError, exception); throw new FutException(string.Format("Unknown EA error, please report it on GitHub - {0}", newException.Message), newException); } }