Class ProviderErrorMappers

java.lang.Object
com.tnsai.llm.errors.ProviderErrorMappers

public final class ProviderErrorMappers extends Object
Static lookup facade for ProviderErrorMappers registered via ServiceLoader.

Provider clients call forProvider(String) when they catch an HTTP error and need to convert it to a typed LLMException. Mappers are loaded lazily the first time the registry is consulted, then cached for the lifetime of the JVM. Replacement is intentionally not supported — the SPI is the configuration mechanism.

Since:
0.5.0 (issue #87)
  • Method Details

    • forProvider

      public static Optional<ProviderErrorMapper> forProvider(String providerId)
      Parameters:
      providerId - lowercase provider identifier (e.g. "openai"); matched against ProviderErrorMapper.providerId()
      Returns:
      the mapper for the given provider, or empty if no SPI implementation is registered
    • reload

      public static void reload()
      Force a re-scan of the SPI. Primarily a test hook so unit tests can register mock mappers via a custom classloader and have them picked up. Production code should not need to call this.