Skip to content

Commit 7776339

Browse files
committed
Adds ORM own type of errors (dresende#455)
1 parent 11d0f75 commit 7776339

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lib/ErrorCodes.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,32 @@ Object.defineProperty(exports, "PARAM_MISSMATCH", {
1717

1818
Object.defineProperty(exports, "generateError", {
1919
value: function (code, message, extra) {
20-
var err = new Error(message);
21-
err.code = code;
20+
var err = new ORMError(message);
21+
22+
err.setCode(code);
2223

2324
if (extra) {
24-
for (var k in extra) {
25-
err[k] = extra[k];
26-
}
25+
err.setExtra(extra);
2726
}
2827

2928
return err;
3029
},
3130
enumerable : false
3231
});
32+
33+
function ORMError(message) {
34+
this.message = message;
35+
}
36+
37+
ORMError.prototype = new Error();
38+
ORMError.prototype.constructor = ORMError;
39+
40+
ORMError.prototype.setCode = function (code) {
41+
this.code = code;
42+
};
43+
44+
ORMError.prototype.setExtra = function (extra) {
45+
for (var k in extra) {
46+
this[k] = extra[k];
47+
}
48+
};

0 commit comments

Comments
 (0)