Skip to content

Commit

Permalink
trigger error event if peaks file cannot be found (#124)
Browse files Browse the repository at this point in the history
* use absolute path

* trigger error event if peaks file cannot be found
  • Loading branch information
thijstriemstra authored Jan 24, 2021
1 parent 59a30f9 commit 258233a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# videojs-wavesurfer changelog

## 3.4.0 - unreleased

- Trigger error event if peaks file cannot be found (#124)


## 3.3.1 - 2020/09/30

- Doc fixes and updated dependencies


## 3.3.0 - 2020/08/10

- Fixed webpack externals configuration: it's no longer needed to use additional webpack
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = function(config) {
colors: true,
reporters: ['verbose', 'progress', 'coverage'],
coverageReporter: {
dir: 'coverage',
dir: path.resolve(__dirname, 'coverage'),
reporters: [
{ type: 'html', subdir: 'html' },
{ type: 'lcov', subdir: 'lcov' }
Expand Down
9 changes: 4 additions & 5 deletions src/js/videojs.wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,10 @@ class Wavesurfer extends Plugin {
this.log(err, 'error');
}
});
request.on('error', e => {
this.log('Unable to retrieve peak data from ' + peaks +
'. Status code: ' + request.response.status, 'warn');
this.log('Loading URL: ' + url);
this.surfer.load(url);
request.once('error', e => {
this.player.trigger(Event.ERROR,
'Unable to retrieve peak data from ' + peaks +
'. Status code: ' + request.response.status);
});
}
}
Expand Down
8 changes: 6 additions & 2 deletions test/videojs.wavesurfer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,13 @@ describe('Wavesurfer', () => {
});

/** @test {Wavesurfer#load} */
it('ignores peaks if file cannot be found', (done) => {
it('throws error if peaks file cannot be found', (done) => {

player.one(Event.WAVE_READY, done);
player.one(Event.ERROR, (element, err) => {
expect(err).toStartWith('Unable to retrieve peak data from non_existing_file.json.');
expect(err).toEndWith('Status code: 404');
done();
});

// try loading from non-existing peaks file
player.src({
Expand Down

0 comments on commit 258233a

Please sign in to comment.