Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change file destroy error message #1257

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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