|
|
@@ -15,7 +15,7 @@ const BASE64_HEADER_REG_EXP = /^data:(\S*?);base64,/;
|
|
|
/**
|
|
|
* FileUploader class used to upload single file.
|
|
|
*/
|
|
|
-class FileUploader {
|
|
|
+export default class FileUploader {
|
|
|
/**
|
|
|
* Creates `FileUploader` instance.
|
|
|
*
|
|
|
@@ -25,15 +25,25 @@ class FileUploader {
|
|
|
*/
|
|
|
constructor( fileOrData, token, apiAddress ) {
|
|
|
if ( !fileOrData ) {
|
|
|
- throw new Error( 'File must be provided' );
|
|
|
+ throw new CKEditorError( 'File must be provided' );
|
|
|
}
|
|
|
|
|
|
if ( !token ) {
|
|
|
- throw new Error( 'Token must be provided' );
|
|
|
+ /**
|
|
|
+ * Token must be provided.
|
|
|
+ *
|
|
|
+ * @error fileuploader-missing-token
|
|
|
+ */
|
|
|
+ throw new CKEditorError( 'fileuploader-missing-token: Token must be provided.' );
|
|
|
}
|
|
|
|
|
|
if ( !apiAddress ) {
|
|
|
- throw new Error( 'Api address must be provided' );
|
|
|
+ /**
|
|
|
+ * Api address must be provided.
|
|
|
+ *
|
|
|
+ * @error fileuploader-missing-api-address
|
|
|
+ */
|
|
|
+ throw new CKEditorError( 'fileuploader-missing-api-address: Api address must be provided.' );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -177,7 +187,12 @@ class FileUploader {
|
|
|
|
|
|
if ( statusCode < 200 || statusCode > 299 ) {
|
|
|
if ( xhrResponse.message ) {
|
|
|
- return reject( new Error( xhrResponse.message ) );
|
|
|
+ /**
|
|
|
+ * Uploading file failed.
|
|
|
+ *
|
|
|
+ * @error fileuploader-uploading-data-failed
|
|
|
+ */
|
|
|
+ return reject( new CKEditorError( 'fileuploader-uploading-data-failed: Uploading file failed.', { message: xhrResponse.message } ) );
|
|
|
}
|
|
|
|
|
|
return reject( xhrResponse.error );
|
|
|
@@ -238,7 +253,12 @@ function _base64ToBlob( base64, sliceSize = 512 ) {
|
|
|
|
|
|
return new Blob( byteArrays, { type: contentType } );
|
|
|
} catch ( error ) {
|
|
|
- throw new Error( 'Problem with decoding Base64 image data.' );
|
|
|
+ /**
|
|
|
+ * Problem with decoding Base64 image data.
|
|
|
+ *
|
|
|
+ * @error fileuploader-decoding-image-data-error
|
|
|
+ */
|
|
|
+ throw new CKEditorError( 'fileuploader-decoding-image-data-error: Problem with decoding Base64 image data.' );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -257,5 +277,3 @@ function _isBase64( string ) {
|
|
|
const match = string.match( BASE64_HEADER_REG_EXP );
|
|
|
return !!( match && match.length );
|
|
|
}
|
|
|
-
|
|
|
-export default FileUploader;
|