All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.knowm.xchange.cryptonit2.dto.CryptonitException Maven / Gradle / Ivy

There is a newer version: 5.0.3
Show newest version
package org.knowm.xchange.cryptonit2.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collection;
import java.util.Map;
import si.mazi.rescu.HttpStatusExceptionSupport;

public class CryptonitException extends HttpStatusExceptionSupport {

  private Map> errors;

  public CryptonitException(
      @JsonProperty("error") Object error, @JsonProperty("reason") Object reason) {
    super(getMessage(error == null ? reason : error));

    if (error == null) {
      error = reason;
    }
    if (error instanceof Map) {
      try {
        errors = (Map>) error;
      } catch (Exception ignore) {
      }
    }
  }

  private static String getMessage(Object errors) {
    if (errors instanceof Map) {
      try {
        Map map = (Map) errors;
        final StringBuilder sb = new StringBuilder();
        for (String key : map.keySet()) {
          for (Object msg : map.get(key)) {
            if (sb.length() > 0) {
              sb.append(" -- ");
            }
            sb.append(msg);
          }
        }
        return sb.toString();
      } catch (Exception ignore) {
      }
    }
    return String.valueOf(errors);
  }

  public Map> getErrors() {
    return errors;
  }

  public Collection getErrors(String key) {
    return errors.get(key);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy