Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #90 from ckeditor/t/ckeditor5-image/263
Browse files Browse the repository at this point in the history
Other: Add catch block for failed file promise in `FileRepository`.
  • Loading branch information
jodator authored Jan 22, 2019
2 parents f6e27cb + 83b78bd commit a2de5d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export default class FileRepository extends Plugin {
} );
}

// Catch the file promise rejection. If there are no `catch` clause, the browser
// will throw an error (see https://github.com/ckeditor/ckeditor5-upload/pull/90).
loader.file.catch( () => {
// The error will be handled by `FileLoader` so no action is required here.
} );

loader.on( 'change:uploaded', () => {
let aggregatedUploaded = 0;

Expand Down
18 changes: 18 additions & 0 deletions tests/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ describe( 'FileRepository', () => {
expect( fileRepository.uploadTotal ).to.equal( 500 );
expect( fileRepository.uploadedPercent ).to.equal( 20 );
} );

it( 'should catch if file promise rejected (file)', () => {
const catchSpy = testUtils.sinon.spy( Promise.prototype, 'catch' );

fileRepository.createLoader( createNativeFileMock() );

// One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
expect( catchSpy.callCount ).to.equal( 2 );
} );

it( 'should catch if file promise rejected (promise)', () => {
const catchSpy = testUtils.sinon.spy( Promise.prototype, 'catch' );

fileRepository.createLoader( new Promise( () => {} ) );

// One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
expect( catchSpy.callCount ).to.equal( 2 );
} );
} );

describe( 'getLoader()', () => {
Expand Down

0 comments on commit a2de5d5

Please sign in to comment.