Class BetterStackErrors

java.lang.Object
codes.grow.packages.betterstack.BetterStackErrors

public final class BetterStackErrors extends Object
Better Stack specific error mapping on top of the SPEC section 2.1 HTTP mapping.
  • Ingest host: 403 (invalid or missing source token) becomes AuthenticationException; 402 (quota or spending limit) becomes a non-retryable QuotaExceededException; 406/413 stay ValidationException.
  • SQL host: the ClickHouse exception code (Code: 60. DB::Exception: …) wins over the HTTP status: 516/192/193/194 authentication, 497 permission denied, 60/81 not found, 62/47/46/36/53/42/73/456/457/241 validation, 48 unsupported, 159/160 timeout, 202 rate limited (retryable).
  • Field Details

    • MEMORY_HINT

      public static final String MEMORY_HINT
      Hint appended to ClickHouse MEMORY_LIMIT_EXCEEDED (241) errors.
      See Also:
  • Method Details

    • mapIngestError

      public static BetterStackException mapIngestError(Throwable error, String operation)
      Maps an ingest-host failure (see the class description). Other errors are returned unchanged.
      Parameters:
      error - failure (may be wrapped in a CompletionException)
      operation - operation name for non-SDK failures
      Returns:
      the mapped SDK exception
    • clickHouseCode

      public static OptionalInt clickHouseCode(String text)
      Extracts the ClickHouse exception code from an error text (Code: 60. DB::Exception: …).
      Parameters:
      text - error text, may be null
      Returns:
      the code, or empty
    • errorForClickHouseCode

      public static Optional<BetterStackException> errorForClickHouseCode(int code, String message, Integer httpStatus, String requestId)
      Builds the SDK exception for a ClickHouse exception code, or empty when the code has no specific mapping (the HTTP status mapping applies then).
      Parameters:
      code - ClickHouse exception code
      message - redacted message
      httpStatus - HTTP status or null
      requestId - request id or null
      Returns:
      the exception, or empty
    • mapQueryError

      public static BetterStackException mapQueryError(Throwable error, String operation)
      Maps a SQL-host failure by the ClickHouse code found in its message; otherwise the error is returned unchanged.
      Parameters:
      error - failure (may be wrapped)
      operation - operation name for non-SDK failures
      Returns:
      the mapped SDK exception