Skip to content

Commit c8f4c81

Browse files
committed
fix(error): throw AV.Error for server exceptions
1 parent f6e4c0b commit c8f4c81

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ module.exports = function(AV) {
342342
if (result.success) {
343343
return result.success;
344344
}
345-
const error = new Error(
345+
const error = new AVError(
346+
result.error.code,
346347
result.error.error || 'Unknown batch error'
347348
);
348-
error.code = result.error.code;
349349
throw error;
350350
});
351351
}

src/request.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const _ = require('underscore');
22
const md5 = require('md5');
33
const { extend } = require('underscore');
44
const AV = require('./av');
5+
const AVError = require('./error');
56
const { getSessionToken } = require('./utils');
67
const ajax = require('./utils/ajax');
78

@@ -149,7 +150,7 @@ const request = ({
149150
}
150151
// Transform the error into an instance of AVError by trying to parse
151152
// the error string as JSON.
152-
const err = new Error(errorJSON.error);
153+
const err = new AVError(errorJSON.code, errorJSON.error);
153154
delete errorJSON.error;
154155
throw _.extend(err, errorJSON);
155156
})

0 commit comments

Comments
 (0)