knex-generic-errors ![Build Status](https://camo.githubusercontent.com/70228ce8c2bb769440906f0819c5d0f18d4086ea94331762b447cc5cc6556064/68747470733a2f2f7472617669732d63692e6f72672f76656c6c6f7469732f6b6e65782d67656e657269632d6572726f72732e7376673f6272616e63683d6d6173746572)
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:
Installation
$ npm install knex-generic-errors --save-dev
Usage
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
API
knex-generic-errors
Errors
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.
Running Tests
Tests can be runned without any database in place.
$ npm install
$ npm test
Copyright and License
Copyright Kaarel Raspel, 2016