rethinkdb / rethinkdb-example-nodejs

137 stars 98 forks source link

Update app.js #2

Closed charlesponti closed 8 years ago

charlesponti commented 9 years ago

Switch error and res arguments for handleError function to use NodeJS convention of passing errors as the first argument.

neumino commented 9 years ago

The convention I think, is to pass the error as the first argument in a callback for an asynchronous operation (that will check for errors). handleError doesn't check for errors, and always take an error as the second argument.

The syntax for handleError could have been handleError(res, message), it's just that it was less work to callhandleError(res, error) instead.

A quick search on GitHub provides examples like these: https://github.com/stevoland/ukc-api/blob/ff2b08e72411daa466fdaf2c6e080d32ef8c00af/src/helpers/ResponseHelper.js https://github.com/Jacqued/quetzal-server/blob/master/modules/handleError.js

So I'm not sure the contention expands to all functions taking an error as an argument. Or maybe I'm missing something? @theponti -- do you have any link that points to the convention for functions that are not callback for asynchronous operations?

danielmewes commented 8 years ago

Closing since this has been inactive for a while.