GithubHelp home page GithubHelp logo

Comments (2)

bsubedi26 avatar bsubedi26 commented on May 22, 2024

@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.

stale avatar stale commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.