loopbackio / strong-error-handler

Error handler for use in development (debug) and production environments.
Other
38 stars 36 forks source link

Customize HTML templates #3

Open loay opened 8 years ago

loay commented 8 years ago

Customize html templates in strong-error-handler, see https://github.com/strongloop/loopback/issues/1650#issuecomment-161920555 for details.

Configuration options:

// map of templates to use for rendering responses
views: {
  // the default view
  default: path.resolve(__dirname, 'views/error-default.jade'),
  404: path.resolve(__dirname, 'views/error-not-found.jade'),
  // etc.
},

// map of static files to send as a response
files: {
  // default: path.resolve(__dirname, 'public/error.html'),
  401: path.resolve(__dirname, 'views/error-unauthorized.html'),
  // etc.
},

Requires #5

michaelfreund commented 7 years ago

+1

michaelfreund commented 7 years ago

what about something like

"final:after": {
  "strong-error-handler": {
    "params": {
      "debug": true,
      "log": false,
      "htmlRenderer": "$!../path/to/html-renderer",
      "jsonRenderer": "$!../path/to/json-renderer",
      "xmlRenderer": "$!../path/to/xml-renderer",
      "jsonSerializer": "$!../path/to/json-serializer"
    }
  }
}
charlie-s commented 7 years ago

See my attempt to roll this in: https://github.com/charlie-s/strong-error-handler/commit/c2335b34d213eaa2d8f3f658e957401ec4dcc036

Note that the order of arguments in negotiateContentProducer seemed to be incorrect (https://github.com/strongloop/strong-error-handler/issues/46) so that fix was included in this commit.

charlie-s commented 7 years ago

Using the above configuration and a function like

module.exports = function sendText(res, data) {
  let content = `${data.name}: ${data.message} (${data.details}) [${data.code}]`;
  res.setHeader('Content-Type', 'plain/text; charset=utf-8');
  res.end(content, 'utf-8');
};

would this help address #6 as well?

selfagency commented 7 years ago

is this ever going to be implemented?