koajs / json-error

Error handler for pure-JSON apps
MIT License
91 stars 3 forks source link

Consider adding a simple format function #32

Closed nfantone closed 8 years ago

nfantone commented 8 years ago

This is meant to simplify the current API and offer an alternative to the preFormat, format, postFormat functions, which may be confusing some users.

In addition to allow passing an options object, we may benefit from receiving a single function instead which should behave as a shorthand for:

let opts = {
   format: (err) => {
      let obj = {};
      // Modify `obj` in any way
      return obj;
   }
}
app.use(error(opts));

So, the above should be equivalent to:

function formatError(err) {
  let obj = {};
  // Modify `obj` in any way
  return obj;
} 
app.use(error(formatError));

Docs should also be updated.

nfantone commented 8 years ago

Implemented in 3.1.0.