CKEditorError (utils)
@ckeditor/ckeditor5-utils/src/ckeditorerror
The CKEditor error class.
You should throw CKEditorError
when:
- An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be handled by the watchdog (if it is integrated),
- If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give
feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not
stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use
logWarning()
andlogError()
to improve developers experience and let them see the a working editor as soon as possible.
/**
* Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
*
* @error plugin-load
* @param pluginName The name of the plugin that could not be loaded.
* @param moduleName The name of the module which tried to load this plugin.
*/
throw new CKEditorError( 'plugin-load', {
pluginName: 'foo',
moduleName: 'bar'
} );
Filtering
Properties
-
A context of the error by which the Watchdog is able to determine which editor crashed.
-
The additional error data passed to the constructor. Undefined if none was passed.
Methods
-
constructor( errorName, [ context ], [ data ] )
module:utils/ckeditorerror~CKEditorError#constructor
Creates an instance of the CKEditorError class.
Parameters
errorName : string
The error id in an
error-name
format. A link to this error documentation page will be added to the thrown error'smessage
.[ context ] : null | object
A context of the error by which the watchdog is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also a
null
value if the editor should not be restarted in case of the error (e.g. during the editor initialization). The error context should be checked using theareConnectedThroughProperties( editor, context )
utility to check if the object works as the context.[ data ] : object
Additional data describing the error. A stringified version of this object will be appended to the error message, so the data are quickly visible in the console. The original data object will also be later available under the
data
property.
-
is( type ) → boolean
module:utils/ckeditorerror~CKEditorError#is
Checks if the error is of the
CKEditorError
type.Parameters
type : string
Returns
boolean
Static methods
-
static
rethrowUnexpectedError( err, context ) → never
module:utils/ckeditorerror~CKEditorError.rethrowUnexpectedError
A utility that ensures that the thrown error is a
CKEditorError
one. It is useful when combined with theWatchdog
feature, which can restart the editor in case of aCKEditorError
error.Parameters
err : Error
The error to rethrow.
context : object
An object connected through properties with the editor instance. This context will be used by the watchdog to verify which editor should be restarted.
Returns
never
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.