Skip to content

Commit

Permalink
fix(GridFS): emit error on bad options
Browse files Browse the repository at this point in the history
Errors related to handling the start/end options for createDownloadStream
did not propagate correctly.

NODE-2623
  • Loading branch information
emadum authored and mbroadst committed Jul 3, 2020
1 parent 272bc18 commit 21b8ae9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/gridfs-stream/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ function init(self: any) {
if (error) {
return __handleError(self, error);
}

if (!doc) {
var identifier = self.s.filter._id ? self.s.filter._id.toString() : self.s.filter.filename;
var errmsg = 'FileNotFound: file ' + identifier + ' was not found';
Expand All @@ -288,7 +289,11 @@ function init(self: any) {
return;
}

self.s.bytesToSkip = handleStartOption(self, doc, self.s.options);
try {
self.s.bytesToSkip = handleStartOption(self, doc, self.s.options);
} catch (error) {
return __handleError(self, error);
}

var filter: any = { files_id: doc._id };

Expand All @@ -309,7 +314,13 @@ function init(self: any) {

self.s.expectedEnd = Math.ceil(doc.length / doc.chunkSize);
self.s.file = doc;
self.s.bytesToTrim = handleEndOption(self, doc, self.s.cursor, self.s.options);

try {
self.s.bytesToTrim = handleEndOption(self, doc, self.s.cursor, self.s.options);
} catch (error) {
return __handleError(self, error);
}

self.emit('file', doc);
});
}
Expand Down

0 comments on commit 21b8ae9

Please sign in to comment.