code: function(err, req, res, next) { // 'next' has to be here, so that this callback works as a final error handler instead of a normal middleware
  		logger.error(req.method, req.originalUrl, err);
  		if (res.finished) {
  			return;
  		}
  		if (err) {
  			res.status(err.status || 500);
  		} else {
  			res.status(404);
  		}
  
  		// respond with json
  		if (req.accepts('json')) {
  			api.writeResponse(null, res, null, { error: err ? err.message : 'Not found' });
  			return;
  		}
  		
  		// default to plain-text. send()
  		api.writeResponse(null, res, {"Content-Type":'text/plain'}, err ? err.message : 'Not found');
  	}
docs: /* @callback