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

enterprises.orbital.impl.evexmlapi.ApiError Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package enterprises.orbital.impl.evexmlapi;

import java.util.Date;

import enterprises.orbital.impl.evexmlapi.utils.DateUtils;

/**
 * Class encapsulating an API error result.
 */
public class ApiError {
  private int    code;
  private String error;
  private Date   retryAfterDate = null;

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getError() {
    return error;
  }

  public void setError(String error) {
    this.error = error;
    try {
      int retryIndex = error.indexOf("retry after ");
      if (retryIndex > 0) {
        int beginIndex = retryIndex + 12;
        String substring = error.substring(beginIndex, beginIndex + 19);
        retryAfterDate = DateUtils.getGMTConverter().convert(Date.class, substring);
      }
    } catch (Exception e) {
      // ignore.
    }
  }

  public boolean hasRetryAfterDate() {
    return retryAfterDate != null;
  }

  public Date getRetryAfterDate() {
    return retryAfterDate;
  }

  @Override
  public String toString() {
    return code + ": " + error;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy