<commit_before>/**
 * Simple auth middleware for Express.js apps that works with Anvil Connect
 * server and node client.
 * @module anvil-connect-express
 */
module.exports = AnvilConnectExpress

/**
 * Module dependencies
 */
var AnvilConnect = require('anvil-connect-nodejs')
var UnauthorizedError = AnvilConnect.UnauthorizedError

/**
 * @class AnvilConnectExpress
 * @constructor
 * @param [options] {Object} Options hashmap (passed through to the Client)
 * @param [options.respond=true] {Boolean} Whether to write an error to the
 *   response object (passes it downstream if set to false)
 */
function AnvilConnectExpress (options) {
  options = options || {}
  this.client = new AnvilConnect(options)
  this.respond = options.respond || true
}

/**
 * Returns an Express handler for http error responses.
 * @method errorHandler
 * @param req {IncomingMessage} Express request object
 * @param res {ServerResponse} Express response object
 * @param next {Function} Express next() callback
 * @return {Function} Error handler
 */
function errorHandler (req, res, next) {
  var self = this

  return function (err) {
    var statusCode = err.statusCode || 400

    if (self.respond) {
      res.status(statusCode).json({
        error: err.error,
        error_description: err.error_description
      })
    } else {
      next(err)
    }<commit_msg>Fix options.respond=true default behavior<commit_after>/**
 * Simple auth middleware for Express.js apps that works with Anvil Connect
 * server and node client.
 * @module anvil-connect-express
 */
module.exports = AnvilConnectExpress

/**
 * Module dependencies
 */
var AnvilConnect = require('anvil-connect-nodejs')
var UnauthorizedError = AnvilConnect.UnauthorizedError

/**
 * @class AnvilConnectExpress
 * @constructor
 * @param [options] {Object} Options hashmap (passed through to the Client)
 * @param [options.respond=true] {Boolean} Whether to write an error to the
 *   response object (passes it downstream if set to false)
 */
function AnvilConnectExpress (options) {
  options = options || {}
  this.client = new AnvilConnect(options)
  this.respond = 'respond' in options ? options.respond : true
}

/**
 * Returns an Express handler for http error responses.
 * @method errorHandler
 * @param req {IncomingMessage} Express request object
 * @param res {ServerResponse} Express response object
 * @param next {Function} Express next() callback
 * @return {Function} Error handler
 */
function errorHandler (req, res, next) {
  var self = this

  return function (err) {
    var statusCode = err.statusCode || 400

    if (self.respond) {
      res.status(statusCode).json({
        error: err.error,
        error_description: err.error_description
      })
    } else {
      next(err)
    }
{'fraction_non_alphanumeric': 0.10339840925524223, 'fraction_numerical': 0.0021691973969631237, 'mean_word_length': 3.8289703315881325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1604372', 'n_tokens_mistral': 768, 'n_tokens_neox': 752, 'n_words': 260}