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

io.contek.invoker.commons.actor.http.ParsedHttpException Maven / Gradle / Ivy

There is a newer version: 3.8.0
Show newest version
package io.contek.invoker.commons.actor.http;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import static java.lang.String.format;

@NotThreadSafe
public final class ParsedHttpException extends AnyHttpException {

  private final Object parsedEntity;

  public ParsedHttpException(int code, Object parsedEntity, String message) {
    super(code, message);
    this.parsedEntity = parsedEntity;
  }

  public Object getParsedEntity() {
    return parsedEntity;
  }

  public  T getParsedEntityAs(Class type) {
    T result = tryGetParsedEntityAs(type);
    if (result == null) {
      throw new ClassCastException(
          format("Expected error type: %s, actual type: %s", type, parsedEntity.getClass()));
    }
    return result;
  }

  @Nullable
  public  T tryGetParsedEntityAs(Class type) {
    if (type.isAssignableFrom(parsedEntity.getClass())) {
      return type.cast(parsedEntity);
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy