Browse Source

Added context to thrown `CKEditorError`s.

Maciej Bukowski 6 years ago
parent
commit
d114f5b1a8

+ 4 - 1
packages/ckeditor-cloud-services-core/src/token/token.js

@@ -38,7 +38,10 @@ class Token {
 			 *
 			 * @error token-missing-token-url
 			 */
-			throw new CKEditorError( 'token-missing-token-url: A `tokenUrl` must be provided as the first constructor argument.' );
+			throw new CKEditorError(
+				'token-missing-token-url: A `tokenUrl` must be provided as the first constructor argument.',
+				this
+			);
 		}
 
 		/**

+ 4 - 4
packages/ckeditor-cloud-services-core/src/uploadgateway/fileuploader.js

@@ -31,7 +31,7 @@ export default class FileUploader {
 			 *
 			 * @error fileuploader-missing-file
 			 */
-			throw new CKEditorError( 'fileuploader-missing-file: File must be provided as the first argument' );
+			throw new CKEditorError( 'fileuploader-missing-file: File must be provided as the first argument', null );
 		}
 
 		if ( !token ) {
@@ -40,7 +40,7 @@ export default class FileUploader {
 			 *
 			 * @error fileuploader-missing-token
 			 */
-			throw new CKEditorError( 'fileuploader-missing-token: Token must be provided as the second argument.' );
+			throw new CKEditorError( 'fileuploader-missing-token: Token must be provided as the second argument.', null );
 		}
 
 		if ( !apiAddress ) {
@@ -49,7 +49,7 @@ export default class FileUploader {
 			 *
 			 * @error fileuploader-missing-api-address
 			 */
-			throw new CKEditorError( 'fileuploader-missing-api-address: Api address must be provided as the third argument.' );
+			throw new CKEditorError( 'fileuploader-missing-api-address: Api address must be provided as the third argument.', null );
 		}
 
 		/**
@@ -267,7 +267,7 @@ function _base64ToBlob( base64, sliceSize = 512 ) {
 		 *
 		 * @error fileuploader-decoding-image-data-error
 		 */
-		throw new CKEditorError( 'fileuploader-decoding-image-data-error: Problem with decoding Base64 image data.' );
+		throw new CKEditorError( 'fileuploader-decoding-image-data-error: Problem with decoding Base64 image data.', null );
 	}
 }
 

+ 2 - 2
packages/ckeditor-cloud-services-core/src/uploadgateway/uploadgateway.js

@@ -25,7 +25,7 @@ export default class UploadGateway {
 			 *
 			 * @error uploadgateway-missing-token
 			 */
-			throw new CKEditorError( 'uploadgateway-missing-token: Token must be provided.' );
+			throw new CKEditorError( 'uploadgateway-missing-token: Token must be provided.', null );
 		}
 
 		if ( !apiAddress ) {
@@ -34,7 +34,7 @@ export default class UploadGateway {
 			 *
 			 * @error uploadgateway-missing-api-address
 			 */
-			throw new CKEditorError( 'uploadgateway-missing-api-address: Api address must be provided.' );
+			throw new CKEditorError( 'uploadgateway-missing-api-address: Api address must be provided.', null );
 		}
 
 		/**

+ 3 - 3
packages/ckeditor-cloud-services-core/tests/uploadgateway/uploadgateway.js

@@ -8,18 +8,18 @@
 import FileUploader from '../../src/uploadgateway/fileuploader';
 import UploadGateway from '../../src/uploadgateway/uploadgateway';
 import Token from '../../src/token/token';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'UploadGateway', () => {
 	const token = new Token( 'url', { initValue: 'token', autoRefresh: false } );
 
 	describe( 'constructor()', () => {
 		it( 'should throw error when no token provided', () => {
-			expect( () => new UploadGateway( undefined, 'test' ) ).to.throw( CKEditorError, 'uploadgateway-missing-token' );
+			expectToThrowCKEditorError( () => new UploadGateway( undefined, 'test' ), 'uploadgateway-missing-token' );
 		} );
 
 		it( 'should throw error when no apiAddress provided', () => {
-			expect( () => new UploadGateway( token ) ).to.throw( CKEditorError, 'uploadgateway-missing-api-address' );
+			expectToThrowCKEditorError( () => new UploadGateway( token ), 'uploadgateway-missing-api-address' );
 		} );
 	} );