Skip to content

Commit f951523

Browse files
authored
fix(Error): make AVError returns native Error (#324)
1 parent e1b82e9 commit f951523

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/error.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ const _ = require('underscore');
77

88
// Class used for all objects passed to error callbacks
99
function AVError(code, message) {
10-
this.code = code;
11-
this.message = message;
10+
const error = new Error(message);
11+
error.code = code;
12+
return error;
1213
}
1314

1415
_.extend(AVError, {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ const AVError = require('./error');
4747
*/
4848
AV.Error = (...args) => {
4949
console.warn('AV.Error() is deprecated, and will be removed in next release.');
50-
new AVError(...args);
50+
return new AVError(...args);
5151
};

test/error.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
'use strict';
2-
3-
var TestError = AV.Object.extend("TestError");
4-
describe("error",function(){
5-
6-
it("return error",function(done){
7-
var test = new TestError();
8-
test.set("num",1);
9-
test.save();
10-
var test1 = new TestError();
11-
test.set("num","s");
12-
test.save(null,{
13-
success:function(obj){
14-
debug(obj);
15-
done();
16-
},
17-
error:function(obj,err){
18-
debug(obj);
19-
debug(err);
20-
done();
21-
}
1+
describe('AVError', () => {
2+
it('should be an Error', () => {
3+
try {
4+
throw AV.Error(-1, 'error message');
5+
} catch (error) {
6+
expect(error).to.be.an(Error);
7+
expect(error.stack).to.be.ok();
8+
expect(error.code).to.equal(-1);
9+
expect(error.message).to.equal('error message');
10+
expect(error.toString()).to.contain('error message');
2211
}
23-
);
2412
});
25-
2613
});

0 commit comments

Comments
 (0)