diff --git a/src/ParseError.js b/src/ParseError.js index 4f8b11107..4053e9df9 100644 --- a/src/ParseError.js +++ b/src/ParseError.js @@ -343,6 +343,14 @@ ParseError.INVALID_PUSH_TIME_ERROR = 152; */ ParseError.FILE_DELETE_ERROR = 153; +/** + * Error code indicating an error deleting an unnamed file. + * + * @property {number} FILE_DELETE_UNNAMED_ERROR + * @static + */ +ParseError.FILE_DELETE_UNNAMED_ERROR = 161; + /** * Error code indicating that the application has exceeded its request * limit. diff --git a/src/ParseFile.js b/src/ParseFile.js index ec0a236c6..2d377d302 100644 --- a/src/ParseFile.js +++ b/src/ParseFile.js @@ -12,6 +12,8 @@ import CoreManager from './CoreManager'; import type { FullOptions } from './RESTController'; +const ParseError = require('./ParseError').default; + let XHR = null; if (typeof XMLHttpRequest !== 'undefined') { XHR = XMLHttpRequest; @@ -314,13 +316,13 @@ class ParseFile { /** * Deletes the file from the Parse cloud. - * In Cloud Code and Node only with Master Key + * In Cloud Code and Node only with Master Key. * * @returns {Promise} Promise that is resolved when the delete finishes. */ destroy() { if (!this._name) { - throw new Error('Cannot delete an unsaved ParseFile.'); + throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.'); } const controller = CoreManager.getFileController(); return controller.deleteFile(this._name).then(() => { diff --git a/src/__tests__/ParseFile-test.js b/src/__tests__/ParseFile-test.js index 2b03547bf..e1c41613a 100644 --- a/src/__tests__/ParseFile-test.js +++ b/src/__tests__/ParseFile-test.js @@ -820,7 +820,7 @@ describe('FileController', () => { try { await file.destroy(); } catch (e) { - expect(e.message).toBe('Cannot delete an unsaved ParseFile.'); + expect(e.code).toBe(ParseError.FILE_DELETE_UNNAMED_ERROR); done(); } });