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

io.contek.zeus.client.errors.GatewayClientErrors Maven / Gradle / Ivy

There is a newer version: 2.29.0
Show newest version
package io.contek.zeus.client.errors;

import io.grpc.StatusRuntimeException;

import javax.annotation.concurrent.Immutable;

@Immutable
public final class GatewayClientErrors {

  public static GatewayClientException toClientException(Throwable t) {
    if (t instanceof StatusRuntimeException casted) {
      return toClientException(casted);
    }
    throw new GatewayUnknownException(t);
  }

  private static GatewayClientException toClientException(StatusRuntimeException error) {
    return switch (error.getStatus().getCode()) {
      case UNAVAILABLE, CANCELLED -> new GatewayUnavailableException(error);
      case RESOURCE_EXHAUSTED -> new GatewayRateLimitException(error);
      case INTERNAL -> new GatewayInternalException(error);
      default -> throw new GatewayUnknownException(error);
    };
  }

  private GatewayClientErrors() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy