A module for knex.js that enables using more detailed "typed" errors instead of plain javascript Error
.
Supported knex versions:
- ^0.10
- ^0.11
- ^0.12
Supported dialects:
$ npm install knex-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 knexGenericErrors = require('knex-generic-errors');
// Wrap Knex initializer
var knex = knexGenericErrors.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