Skip to content

Commit b167677

Browse files
committed
Handle error when calling generateFileName
1 parent 3b6a64e commit b167677

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

lib/stores/DataStore.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ class DataStore {
5858
}
5959

6060
const file_id = this.generateFileName(req);
61-
62-
let file;
63-
try {
64-
file = new File(file_id, upload_length, upload_defer_length, upload_metadata);
65-
}
66-
catch (instantiationError) {
67-
console.error(instantiationError);
68-
return reject(500);
69-
}
61+
const file = new File(file_id, upload_length, upload_defer_length, upload_metadata);
7062

7163
return resolve(file);
7264
});

lib/stores/FileStore.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,22 @@ class FileStore extends DataStore {
5151
const upload_length = req.headers['upload-length'];
5252
const upload_defer_length = req.headers['upload-defer-length'];
5353
const upload_metadata = req.headers['upload-metadata'];
54-
54+
console.log(upload_length, upload_defer_length, 'haah')
5555
if (upload_length === undefined && upload_defer_length === undefined) {
5656
return reject(412);
5757
}
5858

59-
const file_id = this.generateFileName(req);
60-
let file;
59+
let file_id;
6160
try {
62-
file = new File(file_id, upload_length, upload_defer_length, upload_metadata);
61+
file_id = this.generateFileName(req);
6362
}
64-
catch (instantiationError) {
65-
console.error(instantiationError);
63+
catch (generateError) {
64+
console.warn('[FileStore] create: check your namingFunction. Error', generateError);
6665
return reject(500);
6766
}
6867

68+
const file = new File(file_id, upload_length, upload_defer_length, upload_metadata);
69+
6970
return fs.open(`${this.directory}/${file.id}`, 'w', (err, fd) => {
7071
if (err) {
7172
console.warn('[FileStore] create: Error', err);

0 commit comments

Comments
 (0)