A module for knex.js that enables using more detailed "typed" errors instead of plain javascript Error
.
Supported knex versions:
- ^0.10
- ^0.11
Supported dialects:
$ npm install nex-generic-errors --save-dev
As Knex actually doesn't have an API for plugins this module has to be used as seen below.
var Knex = require('knex');
var knexPing = require('knex-ping');
// Wrap Knex initializer
var knex = knexPing.attach(Knex, function() {
// Initialize Knex
return Knex(/* connection configuration */);
});
// Use `knex`
knex.raw('SELECT * FROM')
.catch(Knex.Errors.QueryError, function(err){
/* eg. log query error */
});
knexGenericErrors.Errors === Knex.Errors; // true
knex.Errors === Knex.Errors; // true
Following errors can be accessed through knex-generic-errors property Errors
or after attaching to instance from Knex.Errors
or knex instance knex.Errors
property.
Tests can be runned without any database in place.
$ npm install
$ npm test
Copyright Kaarel Raspel, 2016