Skip to content

Commit

Permalink
error attached directly to constructor instead of returned
Browse files Browse the repository at this point in the history
  • Loading branch information
DubFriend committed Jun 4, 2014
1 parent 142c8b6 commit 9dddb80
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions mysql-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ var MySQLWrapError = function (error) {
};
MySQLWrapError.prototype = Object.create(Error.prototype);

module.exports = function (connection) {
var createMySQLWrap = function (connection) {
'use strict';

var self = {};

self.Error = MySQLWrapError;
// self.Error = MySQLWrapError;

var promiseRespond = function (def, err, res) {
if(err) {
Expand All @@ -44,7 +44,7 @@ module.exports = function (connection) {
};

var respond = function (def, callback, err, res) {
var wrappedError = isMysqlError(err) ? new self.Error(err) : err;
var wrappedError = isMysqlError(err) ? new MySQLWrapError(err) : err;
callback(wrappedError, res);
promiseRespond(def, wrappedError, res);
};
Expand Down Expand Up @@ -250,3 +250,7 @@ module.exports = function (connection) {

return self;
};

createMySQLWrap.Error = MySQLWrapError;

module.exports = createMySQLWrap;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mysql-wrap",
"version": "0.2.3",
"version": "0.3.0",
"description": "Mysql interface and helper functions, wrapping node-mysql",
"main": "mysql-wrap.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ exports.unique_constraint_error = function (test) {
var self = this;
self.sql.insert('table', { unique: 'a'})
.catch(function (err) {
test.ok(err instanceof self.sql.Error);
test.ok(err instanceof createNodeMySQL.Error);
test.strictEqual(err.code, 'ER_DUP_ENTRY', 'error code');
test.strictEqual(err.indexName, 'unique', 'index name');
test.done();
Expand Down

0 comments on commit 9dddb80

Please sign in to comment.