<commit_before>module.exports = ErrorPage

var http = require('http')
, CODES = http.STATUS_CODES
, util = require('util')

function ErrorPage (req, res, opts) {
  opts = opts || {}
  return error

  function error () {
    var code, er, headers, message, handler
    for (var i = 0; i < arguments.length; i ++) {
      var arg = arguments[i]
      switch (typeof arg) {
        case 'number':
          code = arg
          break

        case 'string':
          if (res.template && res.template.has &&
              res.template.has(arg)) {
            handler = arg
          } else {
            message = arg
          }
          break

        case 'function':
          handler = arg
          break

        case 'object':
          if (!arg) break
          if (arg instanceof Error) {
            er = arg
          } else {
            headers = headers || {}
            Object.keys(arg).forEach(function (k) {
              if (k === 'statusCode' ||
                  k === 'cookie' ||
                  k === 'set-cookie') return
              headers[k] = arg[k]
            })
          }
          if (arg.statusCode && !code) code = arg.statusCode
          break
      }
    }

    if (!code) code = 500

    if (!message) {
      if (er) {
        message = opts.debug && er.stack ? er.stack : er.message
      } else {
        message = CODES[code]
      }
    }

    // now we have the args we care about

    // we might have a templater or something hooked up
    var xx = Math.floor(code / 100) + 'xx'<commit_msg>Remove duplication of stack in debug info<commit_after>module.exports = ErrorPage

var http = require('http')
, CODES = http.STATUS_CODES
, util = require('util')

function ErrorPage (req, res, opts) {
  opts = opts || {}
  return error

  function error () {
    var code, er, headers, message, handler
    for (var i = 0; i < arguments.length; i ++) {
      var arg = arguments[i]
      switch (typeof arg) {
        case 'number':
          code = arg
          break

        case 'string':
          if (res.template && res.template.has &&
              res.template.has(arg)) {
            handler = arg
          } else {
            message = arg
          }
          break

        case 'function':
          handler = arg
          break

        case 'object':
          if (!arg) break
          if (arg instanceof Error) {
            er = arg
          } else {
            headers = headers || {}
            Object.keys(arg).forEach(function (k) {
              if (k === 'statusCode' ||
                  k === 'cookie' ||
                  k === 'set-cookie') return
              headers[k] = arg[k]
            })
          }
          if (arg.statusCode && !code) code = arg.statusCode
          break
      }
    }

    if (!code) code = 500

    if (!message) {
      if (er) {
        message = er.message
      } else {
        message = CODES[code]
      }
    }

    // now we have the args we care about

    // we might have a templater or something hooked up
    var xx = Math.floor(code / 100) + 'xx'
{'fraction_non_alphanumeric': 0.11881510416666667, 'fraction_numerical': 0.004557291666666667, 'mean_word_length': 1.3895800933125972, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3043629', 'n_tokens_mistral': 898, 'n_tokens_neox': 862, 'n_words': 264}