Skip to content

Commit 8038fbd

Browse files
committed
error messages update
1 parent 6e43ae4 commit 8038fbd

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

constants/errorMessages.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ module.exports = {
1515
"MISSING_UPLOAD_DATA" : { message : "Missing data for upload", help : "" },
1616
"MISSING_UPLOAD_FILE_PARAMETER" : { message : "Missing file parameter for upload", help : "" },
1717
"MISSING_UPLOAD_FILENAME_PARAMETER" : { message : "Missing fileName parameter for upload", help : "" },
18-
"JOB_ID_MISSING" : { message : "Missing Job ID parameter for this request", help : "" },
19-
"INVALID_FOLDER_PATH" : { messages : "Invalid folder path for this request", help : "Path should be a string like '/path/to/folder'"},
20-
"INVALID_FILE_PATH" : { messages : "Invalid file path for this request", help : "Path should be a string like /path/to/file.jpg'"},
21-
"INVALID_FOLDER_NAME": { messages : "Invalid folder name for this request" , help : ""},
18+
"JOB_ID_MISSING" : { message : "Missing jobId parameter", help : "" },
19+
"INVALID_DESTINATION_FOLDER_PATH" : { messages : "Invalid destinationPath value", help : "It should be a string like '/path/to/folder'"},
20+
"INVALID_SOURCE_FILE_PATH" : { messages : "Invalid sourceFilePath value", help : "It should be a string like /path/to/file.jpg'"},
21+
"INVALID_SOURCE_FOLDER_PATH" : { messages : "Invalid sourceFolderPath value", help : "It should be a string like '/path/to/folder'"},
22+
"INVALID_FOLDER_NAME": { messages : "Invalid folderName value" , help : ""},
23+
"INVALID_PARENT_FOLDER_PATH": { messages : "Invalid parentFolderPath value" , help : "It should be a string like '/path/to/folder'"},
24+
"INVALID_FOLDER_PATH": { messages : "Invalid folderPath value" , help : "It should be a string like '/path/to/folder'"},
2225
// pHash errors
2326
"INVALID_PHASH_VALUE": { message: "Invalid pHash value", help: "Both pHash strings must be valid hexadecimal numbers" },
2427
"MISSING_PHASH_VALUE": { message: "Missing pHash value", help: "Please pass two pHash values" },
2528
"UNEQUAL_STRING_LENGTH": { message: "Unequal pHash string length", help: "For distance calucation, the two pHash strings must have equal length" },
2629
//bulk delete errors
27-
"INVALID_FILEIDS_VALUE": {message: "Invalid value for fileIds", help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId."},
30+
"INVALID_FILEIDS_VALUE": {message: "Invalid value for fileIds", help: "fileIds should be an array of fileId of the files. The array should have atleast one fileId."},
2831
"BULK_ADD_TAGS_INVALID": {message: "Invalid value for tags", help: "tags should be a non empty array of string like ['tag1', 'tag2']."}
2932
};

libs/manage/file.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ module.exports.bulkRemoveTags = function(fileIdArray, tags, defaultOptions, call
213213
module.exports.copyFile = function(sourceFilePath, destinationPath, defaultOptions, callback) {
214214

215215
if(typeof(sourceFilePath) !== 'string' || sourceFilePath.length === 0) {
216-
respond(true, errorMessages.INVALID_FILE_PATH, callback);
216+
respond(true, errorMessages.INVALID_SOURCE_FILE_PATH, callback);
217217
return;
218218
}
219219

220220
if(typeof(destinationPath) !== 'string' || destinationPath.length === 0) {
221-
respond(true, errorMessages.INVALID_FOLDER_PATH, callback);
221+
respond(true, errorMessages.INVALID_DESTINATION_FOLDER_PATH, callback);
222222
return;
223223
}
224224

@@ -242,12 +242,12 @@ module.exports.copyFile = function(sourceFilePath, destinationPath, defaultOptio
242242
module.exports.moveFile = function(sourceFilePath, destinationPath, defaultOptions, callback) {
243243

244244
if(typeof(sourceFilePath) !== 'string' || sourceFilePath.length === 0) {
245-
respond(true, errorMessages.INVALID_FILE_PATH, callback);
245+
respond(true, errorMessages.INVALID_SOURCE_FILE_PATH, callback);
246246
return;
247247
}
248248

249249
if(typeof(destinationPath) !== 'string' || destinationPath.length === 0) {
250-
respond(true, errorMessages.INVALID_FOLDER_PATH, callback);
250+
respond(true, errorMessages.INVALID_DESTINATION_FOLDER_PATH, callback);
251251
return;
252252
}
253253

@@ -270,9 +270,13 @@ module.exports.moveFile = function(sourceFilePath, destinationPath, defaultOptio
270270
*/
271271
module.exports.copyFolder = function(sourceFolderPath, destinationPath, defaultOptions, callback) {
272272

273-
if(typeof(destinationPath) !== 'string' || typeof(sourceFolderPath) !== 'string'
274-
|| destinationPath.length === 0 || sourceFolderPath.length === 0) {
275-
respond(true, errorMessages.INVALID_FOLDER_PATH, callback);
273+
if(typeof(sourceFolderPath) !== 'string' || sourceFolderPath.length === 0) {
274+
respond(true, errorMessages.INVALID_SOURCE_FOLDER_PATH, callback);
275+
return;
276+
}
277+
278+
if(typeof(destinationPath) !== 'string' || destinationPath.length === 0) {
279+
respond(true, errorMessages.INVALID_DESTINATION_FOLDER_PATH, callback);
276280
return;
277281
}
278282

@@ -295,9 +299,13 @@ module.exports.copyFolder = function(sourceFolderPath, destinationPath, defaultO
295299
*/
296300
module.exports.moveFolder = function(sourceFolderPath, destinationPath, defaultOptions, callback) {
297301

298-
if(typeof(destinationPath) !== 'string' || typeof(sourceFolderPath) !== 'string'
299-
|| destinationPath.length === 0 || sourceFolderPath.length === 0) {
300-
respond(true, errorMessages.INVALID_FOLDER_PATH, callback);
302+
if(typeof(sourceFolderPath) !== 'string' || sourceFolderPath.length === 0) {
303+
respond(true, errorMessages.INVALID_SOURCE_FOLDER_PATH, callback);
304+
return;
305+
}
306+
307+
if(typeof(destinationPath) !== 'string' || destinationPath.length === 0) {
308+
respond(true, errorMessages.INVALID_DESTINATION_FOLDER_PATH, callback);
301309
return;
302310
}
303311

@@ -326,7 +334,7 @@ module.exports.createFolder = function(folderName, parentFolderPath, defaultOpti
326334
}
327335

328336
if(typeof(parentFolderPath) !== 'string' || parentFolderPath.length === 0) {
329-
respond(true, errorMessages.INVALID_FOLDER_PATH, callback);
337+
respond(true, errorMessages.INVALID_PARENT_FOLDER_PATH, callback);
330338
return;
331339
}
332340

tests/mediaLibrary.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("Media library APIs", function () {
5858
imagekit.bulkAddTags(null, tags, function (err, response) {
5959
expect(err).to.deep.equal({
6060
message: "Invalid value for fileIds",
61-
help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId."
61+
help: "fileIds should be an array of fileId of the files. The array should have atleast one fileId."
6262
})
6363
done();
6464
});
@@ -69,7 +69,7 @@ describe("Media library APIs", function () {
6969
imagekit.bulkRemoveTags(null, tags, function (err, response) {
7070
expect(err).to.deep.equal({
7171
message: "Invalid value for fileIds",
72-
help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId."
72+
help: "fileIds should be an array of fileId of the files. The array should have atleast one fileId."
7373
})
7474
done();
7575
});
@@ -90,8 +90,8 @@ describe("Media library APIs", function () {
9090
sourceFilePath = "/file.jpg";
9191
imagekit.copyFile(sourceFilePath, null, function (err, response) {
9292
expect(err).to.deep.equal({
93-
messages : "Invalid folder path for this request",
94-
help : "Path should be a string like '/path/to/folder'"
93+
messages : "Invalid destinationPath value",
94+
help : "It should be a string like '/path/to/folder'"
9595
})
9696
done();
9797
});
@@ -101,8 +101,8 @@ describe("Media library APIs", function () {
101101
destinationPath = "/";
102102
imagekit.copyFile(null, destinationPath, function (err, response) {
103103
expect(err).to.deep.equal({
104-
messages : "Invalid file path for this request",
105-
help : "Path should be a string like /path/to/file.jpg'"
104+
messages : "Invalid sourceFilePath value",
105+
help : "It should be a string like /path/to/file.jpg'"
106106
})
107107
done();
108108
});
@@ -112,8 +112,8 @@ describe("Media library APIs", function () {
112112
sourceFilePath = "/file.jpg";
113113
imagekit.moveFile(sourceFilePath, null, function (err, response) {
114114
expect(err).to.deep.equal({
115-
messages : "Invalid folder path for this request",
116-
help : "Path should be a string like '/path/to/folder'"
115+
messages : "Invalid destinationPath value",
116+
help : "It should be a string like '/path/to/folder'"
117117
})
118118
done();
119119
});
@@ -123,8 +123,8 @@ describe("Media library APIs", function () {
123123
destinationPath = "/";
124124
imagekit.moveFile(null, destinationPath, function (err, response) {
125125
expect(err).to.deep.equal({
126-
messages : "Invalid file path for this request",
127-
help : "Path should be a string like /path/to/file.jpg'"
126+
messages : "Invalid sourceFilePath value",
127+
help : "It should be a string like /path/to/file.jpg'"
128128
})
129129
done();
130130
});
@@ -134,8 +134,8 @@ describe("Media library APIs", function () {
134134
sourceFolderPath = "/";
135135
imagekit.copyFolder(sourceFolderPath, null, function (err, response) {
136136
expect(err).to.deep.equal({
137-
messages : "Invalid folder path for this request",
138-
help : "Path should be a string like '/path/to/folder'"
137+
messages : "Invalid destinationPath value",
138+
help : "It should be a string like '/path/to/folder'"
139139
})
140140
done();
141141
});
@@ -145,8 +145,8 @@ describe("Media library APIs", function () {
145145
sourceFolderPath = "/";
146146
imagekit.moveFolder(sourceFolderPath, null, function (err, response) {
147147
expect(err).to.deep.equal({
148-
messages : "Invalid folder path for this request",
149-
help : "Path should be a string like '/path/to/folder'"
148+
messages : "Invalid destinationPath value",
149+
help : "It should be a string like '/path/to/folder'"
150150
})
151151
done();
152152
});
@@ -157,7 +157,7 @@ describe("Media library APIs", function () {
157157
parentFolderPath = "";
158158
imagekit.createFolder(folderName, parentFolderPath, function (err, response) {
159159
expect(err).to.deep.equal({
160-
messages : "Invalid folder name for this request",
160+
messages : "Invalid folderName value",
161161
help : ""
162162
})
163163
done();
@@ -169,8 +169,8 @@ describe("Media library APIs", function () {
169169
parentFolderPath = "";
170170
imagekit.createFolder(folderName, parentFolderPath, function (err, response) {
171171
expect(err).to.deep.equal({
172-
messages : "Invalid folder path for this request",
173-
help : "Path should be a string like '/path/to/folder'"
172+
messages : "Invalid parentFolderPath value",
173+
help : "It should be a string like '/path/to/folder'"
174174
})
175175
done();
176176
});
@@ -179,8 +179,8 @@ describe("Media library APIs", function () {
179179
it('Delete folder invalid path', function (done) {
180180
imagekit.deleteFolder(null, function (err, response) {
181181
expect(err).to.deep.equal({
182-
messages : "Invalid folder path for this request",
183-
help : "Path should be a string like '/path/to/folder'"
182+
messages : "Invalid folderPath value",
183+
help : "It should be a string like '/path/to/folder'"
184184
})
185185
done();
186186
});
@@ -351,7 +351,7 @@ describe("Media library APIs", function () {
351351
imagekit.bulkDeleteFiles(null, function (err, response) {
352352
expect(err).to.deep.equal({
353353
message: "Invalid value for fileIds",
354-
help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId."
354+
help: "fileIds should be an array of fileId of the files. The array should have atleast one fileId."
355355
})
356356
done();
357357
});
@@ -376,7 +376,7 @@ describe("Media library APIs", function () {
376376
imagekit.getBulkJobStatus(null, function (err, response) {
377377
expect(err).to.deep.equal({
378378
help : "" ,
379-
message : "Missing Job ID parameter for this request"
379+
message : "Missing jobId parameter"
380380
})
381381
done();
382382
});

0 commit comments

Comments
 (0)