package org.knowm.xchange.binance;

import org.apache.commons.lang3.StringUtils;
import org.knowm.xchange.binance.dto.BinanceException;
import org.knowm.xchange.exceptions.CurrencyPairNotValidException;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.exceptions.ExchangeSecurityException;
import org.knowm.xchange.exceptions.ExchangeUnavailableException;
import org.knowm.xchange.exceptions.NonceException;
import org.knowm.xchange.exceptions.RateLimitExceededException;

/** @author walec51 */
public final class BinanceErrorAdapter {

  private BinanceErrorAdapter() {}

  public static ExchangeException adapt(BinanceException e) {
    String message = e.getMessage();
    if (StringUtils.isEmpty(message)) {
      message = "Operation failed without any error message";
    }
    switch (e.getCode()) {
      case -1002:
        return new ExchangeSecurityException(message, e);
      case -1003:
        return new RateLimitExceededException(message, e);
      case -1016:
        return new ExchangeUnavailableException(message, e);
      case -1021:
        return new NonceException(message, e);
      case -1121:
        return new CurrencyPairNotValidException(message, e);
      case -1122:
        return new ExchangeSecurityException(message, e);
    }
    return new ExchangeException(message, e);
  }
}

@@ -372,32 +372,92 @@
 lableException;%0A
+import org.knowm.xchange.exceptions.FundsExceededException;%0A
 import org.knowm
@@ -1037,32 +1037,292 @@
 on(message, e);%0A
+      case -1010:%0A      case -2010:%0A      case -2011:%0A        if (e.getMessage().contains(%22insufficient balance%22)) %7B%0A          return new FundsExceededException(e.getMessage(), e);%0A        %7D else %7B%0A          return new ExchangeException(message, e);%0A        %7D%0A
       case -1016

throw FundsExceededException if there is insufficient balance for an operation