Comments (2)
@adrianolsk, I was also trying to implement mapping db error codes (although for mysql) - Here is the issue (#133).
The approach I took was adding the specific database errors: to the response errors object so that it was returned back to the client:
module.exports = function errorHandler (error) {
let feathersError = error;
const { code , errno, sqlMessage } = error;
const errorsObject = Object.assign({}, { code , errno, sqlMessage });
... (rest of the error handler code) ...
}
Then, within the appropriate case statements:
feathersError = new errors.BadRequest(error, { errors: errorsObject });
This achieves the client error to look like this:
"name": "BadRequest",
"message": "insert into `task` (`another_col`, `text`) values ('afssxxsaaxafmA', 'ff') - Duplicate entry 'afssxxsaaxafmA' for key 'task_another_col_unique'",
"code": 400,
"className": "bad-request",
"data": {},
"errors": { <<== Added to this object (previously it was an empty object)
"code": "ER_DUP_ENTRY",
"errno": 1062
}
}
I was looking through the error-handler.js
code, and the way they're detecting postgresql database errors is with this line of code:
if (typeof error.code === 'string' && error.severity && error.routine) { ... }
You could possibly do something similar to this - taken from Objection.js issues (Vincit/objection.js#117) - which also uses knex.js
:
function isPostgresError(error) {
if (!error) { return false; }
// Just check the existence of a bunch of attributes. There doesn't seem to be an easier way.
return _.all(['severity', 'code', 'detail', 'internalQuery', 'routine'], function(attr) {
return _.has(error, attr);
});
}
from feathers-knex.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.
from feathers-knex.
Related Issues (20)
- An in-range update of @feathersjs/adapter-commons is breaking the build 🚨 HOT 2
- An in-range update of knex is breaking the build 🚨 HOT 6
- Add array-type operators HOT 1
- An in-range update of @feathersjs/adapter-commons is breaking the build 🚨 HOT 1
- Feathers Knex generating bad COUNT query when using [$in] operator with only one value (sqlite) HOT 1
- Feathers-knex, REST and PostGIS — include examples? HOT 3
- Create method with knex plugged with mssql database returns no id. Gets General Error in feathers api HOT 2
- An in-range update of knex is breaking the build 🚨 HOT 5
- Closing the database connection / cleanup ? HOT 2
- SQL Server "Cannot read property '0' of undefined" when create HOT 1
- `find` adds the `id` column automatically with no easy way to remove it HOT 1
- No release
- Authenticate Hook => Create an unwanted query parameter 'Authorization' HOT 2
- Cannot use namespace 'Knex' as a type HOT 5
- Dynamically changing the knex schema based on request
- Fix types to work with knex > 0.95
- Re-run migrations? HOT 1
- Meta fields missing (`total`, `skip`, ...) HOT 2
- Paginated results incorrect without $sort
- Search with $ilike a value into a json column type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feathers-knex.