knex
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -54,2 +54,5 @@ // ServerBase | ||
// If the builder came with a supplied connection, then we won't do | ||
// anything to it (most commonly in the case of transactions)... otherwise, | ||
// ensure the connection gets dumped back into the client pool. | ||
if (!builder.usingConnection) { | ||
@@ -61,6 +64,10 @@ chain = chain.ensure(function() { | ||
return chain.then(builder.handleResponse).otherwise(function(e) { | ||
var err = new Error(e.toString() + ' - ' + '{sql: ' + sql + ', bindings: ' + bindings + '}'); | ||
err.originalStack = e.stack; | ||
throw err; | ||
// Since we usually only need the `sql` and `bindings` to help us debug the query, output them | ||
// into a new error... this way, it `console.log`'s nicely for debugging, but you can also | ||
// parse them out with a `JSON.parse(error.message)`. Also, use the original `clientError` from the | ||
// database client is retained as a property on the `newError`, for any additional info. | ||
return chain.then(builder.handleResponse).otherwise(function(error) { | ||
var newError = new Error(JSON.stringify({sql: sql, bindings: bindings})); | ||
newError.clientError = error; | ||
throw newError; | ||
}); | ||
@@ -67,0 +74,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
// Knex.js 0.4.5 | ||
// Knex.js 0.4.6 | ||
// -------------- | ||
@@ -94,3 +94,3 @@ | ||
// Keep in sync with package.json | ||
knex.VERSION = '0.4.5'; | ||
knex.VERSION = '0.4.6'; | ||
@@ -97,0 +97,0 @@ // Runs a new transaction, taking a container and returning a promise |
{ | ||
"name": "knex", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "A query builder for Postgres, MySQL and SQLite3, designed to be flexible, portable, and fun to use.", | ||
@@ -5,0 +5,0 @@ "main": "knex.js", |
@@ -61,4 +61,23 @@ | ||
it('should reject with a custom error, with the sql, bindings, and message, along with a clientError property', function() { | ||
return knex('nonexistent_table').insert([{item: 1}, {item: 2}]).then(null, function(err) { | ||
var obj = JSON.parse(err.message); | ||
expect(obj).to.have.property('sql'); | ||
expect(obj).to.have.property('bindings'); | ||
expect(err).to.have.property('clientError'); | ||
expect(err).to.be.an.instanceOf(Error); | ||
}); | ||
}); | ||
}); | ||
}; |
describe('Server Base', function () { | ||
it('should take a config object in the constructor, to set up the pool, etc.', function() { | ||
it('should take a config object in the constructor, to set up the pool, etc.'); | ||
}); | ||
}); |
220880
5767