Skip to content

Commit 50514f0

Browse files
authored
Change file destroy error message (#1257)
* improved error message when deleting unnamed file * Fixed typo * added new error for deleting unnamed file * added Parse Error reference * changed error code had to change error code again because it was already used
1 parent c9699e2 commit 50514f0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/ParseError.js

+8
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ ParseError.INVALID_PUSH_TIME_ERROR = 152;
343343
*/
344344
ParseError.FILE_DELETE_ERROR = 153;
345345

346+
/**
347+
* Error code indicating an error deleting an unnamed file.
348+
*
349+
* @property {number} FILE_DELETE_UNNAMED_ERROR
350+
* @static
351+
*/
352+
ParseError.FILE_DELETE_UNNAMED_ERROR = 161;
353+
346354
/**
347355
* Error code indicating that the application has exceeded its request
348356
* limit.

src/ParseFile.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import CoreManager from './CoreManager';
1313
import type { FullOptions } from './RESTController';
1414

15+
const ParseError = require('./ParseError').default;
16+
1517
let XHR = null;
1618
if (typeof XMLHttpRequest !== 'undefined') {
1719
XHR = XMLHttpRequest;
@@ -314,13 +316,13 @@ class ParseFile {
314316

315317
/**
316318
* Deletes the file from the Parse cloud.
317-
* In Cloud Code and Node only with Master Key
319+
* In Cloud Code and Node only with Master Key.
318320
*
319321
* @returns {Promise} Promise that is resolved when the delete finishes.
320322
*/
321323
destroy() {
322324
if (!this._name) {
323-
throw new Error('Cannot delete an unsaved ParseFile.');
325+
throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
324326
}
325327
const controller = CoreManager.getFileController();
326328
return controller.deleteFile(this._name).then(() => {

src/__tests__/ParseFile-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ describe('FileController', () => {
820820
try {
821821
await file.destroy();
822822
} catch (e) {
823-
expect(e.message).toBe('Cannot delete an unsaved ParseFile.');
823+
expect(e.code).toBe(ParseError.FILE_DELETE_UNNAMED_ERROR);
824824
done();
825825
}
826826
});

0 commit comments

Comments
 (0)