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

com.xeiam.xchange.bitstamp.dto.BitstampException Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package com.xeiam.xchange.bitstamp.dto;

import java.util.Collection;
import java.util.Map;

import si.mazi.rescu.HttpStatusExceptionSupport;

import com.fasterxml.jackson.annotation.JsonProperty;

public class BitstampException extends HttpStatusExceptionSupport {

  private Map> errors;

  public BitstampException(@JsonProperty("error") Object error) {
    super(getMessage(error));

    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