Interface ErrorHandler

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ErrorHandler
Editor error handler. Used to customize error handling logic such as logging, sending alerts, etc.

Return Value Semantics

The return value of handleError(EditorError) determines error propagation behavior:

  • true - Error fully handled, stop propagation, EditorErrorEvent will not be fired
  • false - Error not fully handled, continue propagation, EditorErrorEvent will be fired

Usage Examples

Basic usage - log but don't block propagation

editor.setErrorHandler(error -> {
    logger.error("CKEditor error [{}]: {}", error.getCode(), error.getMessage());
    return false; // Continue propagation, allow other listeners to handle
});

Conditional handling - only intercept specific errors

editor.setErrorHandler(error -> {
    if ("NETWORK_ERROR".equals(error.getCode())) {
        // Auto-retry network errors, don't propagate to user
        retryService.scheduleRetry();
        return true; // Handled, stop propagation
    }
    return false; // Continue propagation for other errors
});

Chained handling - compose multiple handlers

ErrorHandler logger = ErrorHandler.logging(log);
ErrorHandler alerter = error -> {
    if (error.getSeverity() == ErrorSeverity.FATAL) {
        alertService.sendAlert(error.getMessage());
        return true;
    }
    return false;
};
// Log first, then send alert
editor.setErrorHandler(ErrorHandler.compose(logger, alerter));

Best Practices

  • Loggers should usually return false to allow other handlers to continue processing
  • Only return true when the error is completely resolved (e.g., auto-retry succeeded)
  • For fatal errors (FATAL), usually let them propagate so the UI can respond
  • When using compose(ErrorHandler...), the order of handlers matters
See Also:
  • Method Details

    • handleError

      boolean handleError(EditorErrorEvent.EditorError error)
      Handle an editor error.

      This method is called before EditorErrorEvent is fired, providing an opportunity to intercept and handle the error.

      Parameters:
      error - error details including error code, message, severity, etc.
      Returns:
      true if the error is fully handled, stopping propagation (event not fired); false if the error is not handled or needs to continue propagating (fires EditorErrorEvent)
    • logging

      static ErrorHandler logging(Logger logger)
      Create a logging error handler.
      Parameters:
      logger - the logger instance
      Returns:
      an error handler instance
    • compose

      static ErrorHandler compose(ErrorHandler... handlers)
      Compose multiple error handlers.
      Parameters:
      handlers - the handler list
      Returns:
      a composed handler