Skip to content

Commit

Permalink
Change file destroy error message (#1257)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mtrezza authored Dec 7, 2020
1 parent c9699e2 commit 50514f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/ParseError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ParseFile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down

0 comments on commit 50514f0

Please sign in to comment.