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.
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,EditorErrorEventwill not be firedfalse- Error not fully handled, continue propagation,EditorErrorEventwill 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
falseto allow other handlers to continue processing - Only return
truewhen 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 Summary
Modifier and TypeMethodDescriptionstatic ErrorHandlercompose(ErrorHandler... handlers) Compose multiple error handlers.booleanHandle an editor error.static ErrorHandlerCreate a logging error handler.
-
Method Details
-
handleError
Handle an editor error.This method is called before
EditorErrorEventis fired, providing an opportunity to intercept and handle the error.- Parameters:
error- error details including error code, message, severity, etc.- Returns:
trueif the error is fully handled, stopping propagation (event not fired);falseif the error is not handled or needs to continue propagating (firesEditorErrorEvent)
-
logging
Create a logging error handler.- Parameters:
logger- the logger instance- Returns:
- an error handler instance
-
compose
Compose multiple error handlers.- Parameters:
handlers- the handler list- Returns:
- a composed handler
-