Class ErrorClassifier

java.lang.Object
express.mvp.myra.transport.error.ErrorClassifier

public final class ErrorClassifier extends Object
Classifies exceptions into error categories for recovery decisions.

This classifier uses a combination of exception type matching and message analysis to categorize errors appropriately. Custom classifiers can be registered for application-specific exceptions.

Classification Strategy

  1. Check custom classifiers first (exact type match)
  2. Check for JVM errors (VirtualMachineError, etc.)
  3. Check exception type hierarchy
  4. Analyze exception message for patterns
  5. Default to UNKNOWN if unclassifiable

Usage Example

try {
    transport.send(data);
} catch (Exception e) {
    ErrorCategory category = ErrorClassifier.classify(e);
    if (category.isRetryable()) {
        retryPolicy.handleRetryable(e, category);
    } else {
        handleFatalError(e);
    }
}

Custom Classifiers

// Register custom exception type
ErrorClassifier.registerClassifier(
    MyAppException.class,
    e -> e.isRetryable() ? ErrorCategory.TRANSIENT : ErrorCategory.FATAL
);
See Also:
  • Method Details

    • classify

      public static ErrorCategory classify(Throwable throwable)
      Classifies an exception into an error category.
      Parameters:
      throwable - the exception to classify
      Returns:
      the error category
    • registerClassifier

      public static <T extends Throwable> void registerClassifier(Class<T> exceptionType, Function<Throwable, ErrorCategory> classifier)
      Registers a custom classifier for a specific exception type.

      Custom classifiers are checked before built-in classification. The predicate receives the exception and should return the desired category, or ErrorCategory.UNKNOWN to fall back to built-in classification.

      Type Parameters:
      T - the exception type
      Parameters:
      exceptionType - the exception class to match
      classifier - function that returns a category for the exception
    • removeClassifier

      public static void removeClassifier(Class<? extends Throwable> exceptionType)
      Removes a previously registered custom classifier.
      Parameters:
      exceptionType - the exception class
    • clearCustomClassifiers

      public static void clearCustomClassifiers()
      Clears all custom classifiers.
    • describeError

      public static String describeError(Throwable throwable)
      Returns a detailed description of the classification result.
      Parameters:
      throwable - the exception to describe
      Returns:
      formatted description including category and details