Skip to content

Commit ef4cc3e

Browse files
authored
fix: throws when fetching object without id (#641)
1 parent ead0d9d commit ef4cc3e

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ module.exports = function(AV) {
619619
* completes.
620620
*/
621621
fetch(fetchOptions, options) {
622+
if (!this.id) {
623+
throw new Error('Cannot fetch unsaved file');
624+
}
622625
var request = AVRequest(
623626
'files',
624627
null,

src/object.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,9 @@ module.exports = function(AV) {
946946
* completes.
947947
*/
948948
fetch: function(fetchOptions = {}, options) {
949+
if (!this.id) {
950+
throw new Error('Cannot fetch unsaved object');
951+
}
949952
var self = this;
950953
var request = _request(
951954
'classes',

test/file.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ describe('File', function() {
188188
.fetch()
189189
.then(file => (this.file = file));
190190
});
191+
it('should throws when objectId is empty', () => {
192+
const file = new AV.File('filename', { base64: 'dGVzdA==' });
193+
expect(file.fetch).throwError();
194+
});
191195
it('should retrieve all data', function() {
192196
var file = this.file;
193197
expect(file).to.be.a(AV.File);

test/object.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ describe('Objects', function() {
447447
expect(score.createdAt).to.be.a(Date);
448448
expect(score.id).to.be.eql(gameScore.id);
449449
}));
450+
it('should throws when objectId is empty', () => {
451+
const object = new AV.Object('GameScore');
452+
expect(object.fetch).throwError();
453+
});
450454
it('fetch should remove deleted keys', () => {
451455
const getFakedScore = () =>
452456
AV.parseJSON(

0 commit comments

Comments
 (0)