pax_global_header00006660000000000000000000000064151200537750014517gustar00rootroot0000000000000052 comment=f6bec9f930c1e043f6cb6a5d74e21091269a02e3 expressjs-errorhandler-f6bec9f/000077500000000000000000000000001512005377500170205ustar00rootroot00000000000000expressjs-errorhandler-f6bec9f/.eslintignore000066400000000000000000000000261512005377500215210ustar00rootroot00000000000000coverage node_modules expressjs-errorhandler-f6bec9f/.eslintrc.yml000066400000000000000000000002731512005377500214460ustar00rootroot00000000000000root: true extends: - standard - plugin:markdown/recommended plugins: - markdown overrides: - files: '**/*.md' processor: 'markdown/markdown' rules: no-param-reassign: errorexpressjs-errorhandler-f6bec9f/.github/000077500000000000000000000000001512005377500203605ustar00rootroot00000000000000expressjs-errorhandler-f6bec9f/.github/dependabot.yml000066400000000000000000000005041512005377500232070ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: github-actions directory: / schedule: interval: monthly - package-ecosystem: npm directory: / schedule: interval: monthly open-pull-requests-limit: 10 ignore: - dependency-name: "*" update-types: ["version-update:semver-major"] expressjs-errorhandler-f6bec9f/.github/workflows/000077500000000000000000000000001512005377500224155ustar00rootroot00000000000000expressjs-errorhandler-f6bec9f/.github/workflows/ci.yml000066400000000000000000000155221512005377500235400ustar00rootroot00000000000000name: ci on: push: branches: - master paths-ignore: - '*.md' pull_request: paths-ignore: - '*.md' jobs: test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: name: - Node.js 0.8 - Node.js 0.10 - Node.js 0.12 - io.js 1.x - io.js 2.x - io.js 3.x - Node.js 4.x - Node.js 5.x - Node.js 6.x - Node.js 7.x - Node.js 8.x - Node.js 9.x - Node.js 10.x - Node.js 11.x - Node.js 12.x - Node.js 13.x - Node.js 14.x - Node.js 15.x - Node.js 16.x - Node.js 17.x - Node.js 18.x - Node.js 19.x - Node.js 20.x - Node.js 21.x - Node.js 22.x - Node.js 23.x - Node.js 24.x - Node.js 25.x include: - name: Node.js 0.8 node-version: "0.8" npm-i: mocha@2.5.3 supertest@1.1.0 npm-rm: nyc - name: Node.js 0.10 node-version: "0.10" npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 npm-rm: nyc - name: io.js 1.x node-version: "1" npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 npm-rm: nyc - name: io.js 2.x node-version: "2" npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 npm-rm: nyc - name: io.js 3.x node-version: "3" npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 npm-rm: nyc - name: Node.js 4.x node-version: "4" npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 5.x node-version: "5" npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 6.x node-version: "6" npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 7.x node-version: "7" npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 8.x node-version: "8" npm-i: mocha@7.2.0 nyc@14.1.1 supertest@6.1.6 - name: Node.js 9.x node-version: "9" npm-i: mocha@7.2.0 nyc@14.1.1 supertest@6.1.6 - name: Node.js 10.x node-version: "10" npm-i: mocha@8.4.0 supertest@6.1.6 - name: Node.js 11.x node-version: "11" npm-i: mocha@8.4.0 supertest@6.1.6 - name: Node.js 12.x node-version: "12" npm-i: mocha@9.2.2 supertest@6.1.6 eslint-plugin-standard@4.1.0 - name: Node.js 13.x node-version: "13" npm-i: mocha@9.2.2 supertest@6.1.6 eslint-plugin-standard@4.1.0 - name: Node.js 14.x node-version: "14" npm-i: mocha@9.2.2 supertest@6.1.6 eslint-plugin-standard@4.1.0 - name: Node.js 15.x node-version: "15" npm-i: "supertest@6.1.6" - name: Node.js 16.x node-version: "16" - name: Node.js 17.x node-version: "17" - name: Node.js 18.x node-version: "18" - name: Node.js 19.x node-version: "19" - name: Node.js 20.x node-version: "20" - name: Node.js 21.x node-version: "21" - name: Node.js 22.x node-version: "22" - name: Node.js 23.x node-version: "23" - name: Node.js 24.x node-version: "24" - name: Node.js 25.x node-version: "25" steps: - uses: actions/checkout@v6 - name: Install Node.js ${{ matrix.node-version }} shell: bash -eo pipefail -l {0} run: | nvm install --default ${{ matrix.node-version }} if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then nvm install --alias=npm 0.10 nvm use ${{ matrix.node-version }} sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" npm config set strict-ssl false npm install -g --prefix "$(which node)/../.." npm@1.2.8000 sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" fi dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" - name: Configure npm run: | if [[ "$(npm config get package-lock)" == "true" ]]; then npm config set package-lock false else npm config set shrinkwrap false fi - name: Remove npm module(s) ${{ matrix.npm-rm }} run: npm rm --silent --save-dev ${{ matrix.npm-rm }} if: matrix.npm-rm != '' - name: Install npm module(s) ${{ matrix.npm-i }} run: npm install --save-dev ${{ matrix.npm-i }} if: matrix.npm-i != '' - name: Setup Node.js version-specific dependencies shell: bash run: | # eslint for linting # - remove on Node.js < 12 if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ grep -E '^eslint(-|$)' | \ sort -r | \ xargs -n1 npm rm --silent --save-dev fi - name: Install Node.js dependencies run: npm install - name: List environment id: list_env shell: bash run: | echo "node@$(node -v)" echo "npm@$(npm -v)" npm -s ls ||: (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT" - name: Run tests shell: bash run: | if npm -ps ls nyc | grep -q nyc; then npm run test-ci cp coverage/lcov.info "coverage/${{ matrix.name }}.lcov" else npm test fi - name: Lint code if: steps.list_env.outputs.eslint != '' run: npm run lint - name: Upload code coverage uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 with: name: coverage-node-${{ matrix.node-version }} path: ./coverage/lcov.info retention-days: 1 coverage: needs: test runs-on: ubuntu-latest permissions: contents: read checks: write steps: - uses: actions/checkout@v6 - name: Install lcov shell: bash run: sudo apt-get -y install lcov - name: Collect coverage reports uses: actions/download-artifact@v6 with: path: ./coverage pattern: coverage-node-* - name: Merge coverage reports shell: bash run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info - name: Upload coverage report uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 with: file: ./lcov.infoexpressjs-errorhandler-f6bec9f/.github/workflows/codeql.yml000066400000000000000000000052501512005377500244110ustar00rootroot00000000000000# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. # # ******** NOTE ******** # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # name: "CodeQL" on: push: branches: ["master"] pull_request: # The branches below must be a subset of the branches above branches: ["master"] schedule: - cron: "0 0 * * 1" permissions: contents: read jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: ["javascript"] # CodeQL supports [ $supported-codeql-languages ] # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - name: Checkout repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@fdbfb4d2750291e159f0156def62b853c2798ca2 # v3.29.5 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@fdbfb4d2750291e159f0156def62b853c2798ca2 # v3.29.5 # â„šī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun # If the Autobuild fails above, remove it and uncomment the following three lines. # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. # - run: | # echo "Run, Build Application using script" # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@fdbfb4d2750291e159f0156def62b853c2798ca2 # v3.29.5 with: category: "/language:${{matrix.language}}" expressjs-errorhandler-f6bec9f/.github/workflows/scorecard.yml000066400000000000000000000056461512005377500251200ustar00rootroot00000000000000# This workflow uses actions that are not certified by GitHub. They are provided # by a third-party and are governed by separate terms of service, privacy # policy, and support documentation. name: Scorecard supply-chain security on: # For Branch-Protection check. Only the default branch is supported. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection branch_protection_rule: # To guarantee Maintained check is occasionally updated. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained schedule: - cron: '16 21 * * 1' push: branches: [ "master" ] # Declare default permissions as read only. permissions: read-all jobs: analysis: name: Scorecard analysis runs-on: ubuntu-latest permissions: # Needed to upload the results to code-scanning dashboard. security-events: write # Needed to publish results and get a badge (see publish_results below). id-token: write # Uncomment the permissions below if installing in a private repository. # contents: read # actions: read steps: - name: "Checkout code" uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 with: persist-credentials: false - name: "Run analysis" uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 with: results_file: results.sarif results_format: sarif # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: # - you want to enable the Branch-Protection check on a *public* repository, or # - you are installing Scorecard on a *private* repository # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. # repo_token: ${{ secrets.SCORECARD_TOKEN }} # Public repositories: # - Publish results to OpenSSF REST API for easy access by consumers # - Allows the repository to include the Scorecard badge. # - See https://github.com/ossf/scorecard-action#publishing-results. # For private repositories: # - `publish_results` will always be set to `false`, regardless # of the value entered here. publish_results: true # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 with: name: SARIF file path: results.sarif retention-days: 5 # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" uses: github/codeql-action/upload-sarif@fdbfb4d2750291e159f0156def62b853c2798ca2 # v3.29.5 with: sarif_file: results.sarif expressjs-errorhandler-f6bec9f/.gitignore000066400000000000000000000000701512005377500210050ustar00rootroot00000000000000coverage/ node_modules/ npm-debug.log package-lock.json expressjs-errorhandler-f6bec9f/HISTORY.md000066400000000000000000000066021512005377500205070ustar00rootroot000000000000001.5.2 / 2025-12-15 ================== * deps: accepts": "~1.3.8" - deps: mime-types@~2.1.34 - deps: mime-db@~1.51.0 - deps: negotiator@0.6.3 1.5.1 / 2019-05-08 ================== * deps: accepts@~1.3.7 - deps: mime-types@~2.1.24 - deps: negotiator@0.6.2 1.5.0 / 2016-11-15 ================== * Pretty print JSON error response * deps: accepts@~1.3.3 - deps: mime-types@~2.1.11 - deps: negotiator@0.6.1 * perf: front-load HTML template and stylesheet at middleware construction * perf: only load template and stylesheet once * perf: resolve file paths at start up 1.4.3 / 2016-01-17 ================== * deps: accepts@~1.3.0 - deps: mime-types@~2.1.7 - deps: negotiator@0.6.0 * deps: escape-html@~1.0.3 - perf: enable strict mode - perf: optimize string replacement - perf: use faster string coercion 1.4.2 / 2015-07-30 ================== * deps: accepts@~1.2.12 - deps: mime-types@~2.1.4 1.4.1 / 2015-07-05 ================== * deps: accepts@~1.2.10 - deps: mime-types@~2.1.2 1.4.0 / 2015-06-10 ================== * Add charset to the `Content-Type` header * Support `statusCode` property on `Error` objects * deps: accepts@~1.2.9 - deps: mime-types@~2.1.1 - deps: negotiator@0.5.3 - perf: avoid argument reassignment & argument slice - perf: avoid negotiator recursive construction - perf: enable strict mode - perf: remove unnecessary bitwise operator * deps: escape-html@1.0.2 1.3.6 / 2015-05-14 ================== * deps: accepts@~1.2.7 - deps: mime-types@~2.0.11 - deps: negotiator@0.5.3 1.3.5 / 2015-03-14 ================== * deps: accepts@~1.2.5 - deps: mime-types@~2.0.10 1.3.4 / 2015-02-15 ================== * deps: accepts@~1.2.4 - deps: mime-types@~2.0.9 - deps: negotiator@0.5.1 1.3.3 / 2015-01-31 ================== * deps: accepts@~1.2.3 - deps: mime-types@~2.0.8 1.3.2 / 2015-01-01 ================== * Fix heading content to not include stack 1.3.1 / 2014-12-31 ================== * deps: accepts@~1.2.2 - deps: mime-types@~2.0.7 - deps: negotiator@0.5.0 1.3.0 / 2014-11-22 ================== * Add `log` option 1.2.4 / 2015-01-01 ================== * Fix heading content to not include stack 1.2.3 / 2014-11-21 ================== * deps: accepts@~1.1.3 - deps: mime-types@~2.0.3 1.2.2 / 2014-10-15 ================== * deps: accepts@~1.1.2 - Fix error when media type has invalid parameter - deps: negotiator@0.4.9 1.2.1 / 2014-10-12 ================== * deps: accepts@~1.1.1 - deps: mime-types@~2.0.2 - deps: negotiator@0.4.8 1.2.0 / 2014-09-02 ================== * Display error using `util.inspect` if no other representation * deps: accepts@~1.1.0 1.1.1 / 2014-06-20 ================== * deps: accepts@~1.0.4 - use `mime-types` 1.1.0 / 2014-06-16 ================== * Display error on console formatted like `throw` * Escape HTML with `escape-html` module * Escape HTML in stack trace * Escape HTML in title * Fix up edge cases with error sent in response * Set `X-Content-Type-Options: nosniff` header * Use accepts for negotiation 1.0.2 / 2014-06-05 ================== * Pass on errors from reading error files 1.0.1 / 2014-04-29 ================== * Clean up error CSS * Do not respond after headers sent 1.0.0 / 2014-03-03 ================== * Genesis from `connect` expressjs-errorhandler-f6bec9f/LICENSE000066400000000000000000000022241512005377500200250ustar00rootroot00000000000000(The MIT License) Copyright (c) 2014 Jonathan Ong Copyright (c) 2014-2015 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. expressjs-errorhandler-f6bec9f/README.md000066400000000000000000000077371512005377500203150ustar00rootroot00000000000000# errorhandler [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Test Coverage][coveralls-image]][coveralls-url] Development-only error handler middleware. This middleware is only intended to be used in a development environment, as the _full error stack traces and internal details of any object passed to this module_ will be sent back to the client when an error occurs. When an object is provided to Express as an error, this module will display as much about this object as possible, and will do so by using content negotiation for the response between HTML, JSON, and plain text. * When the object is a standard `Error` object, the string provided by the `stack` property will be returned in HTML/text responses. * When the object is a non-`Error` object, the result of [util.inspect](https://nodejs.org/api/util.html#util_util_inspect_object_options) will be returned in HTML/text responses. * For JSON responses, the result will be an object with all enumerable properties from the object in the response. ## Install This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install errorhandler ``` ## API ```js var errorhandler = require('errorhandler') ``` ### errorhandler(options) Create new middleware to handle errors and respond with content negotiation. #### Options Error handler accepts these properties in the options object. ##### log Provide a function to be called with the error and a string representation of the error. Can be used to write the error to any desired location, or set to `false` to only send the error back in the response. Called as `log(err, str, req, res)` where `err` is the `Error` object, `str` is a string representation of the error, `req` is the request object and `res` is the response object (note, this function is invoked _after_ the response has been written). The default value for this option is `true` unless `process.env.NODE_ENV === 'test'`. Possible values: * `true`: Log errors using `console.error(str)`. * `false`: Only send the error back in the response. * A function: pass the error to a function for handling. ## Examples ### Simple example Basic example of adding this middleware as the error handler only in development with `connect` (`express` also can be used in this example). ```js var connect = require('connect') var errorhandler = require('errorhandler') var app = connect() // assumes NODE_ENV is set by the user if (process.env.NODE_ENV === 'development') { // only use in development app.use(errorhandler()) } ``` ### Custom output location Sometimes you may want to output the errors to a different location than STDERR during development, like a system notification, for example. ```js var connect = require('connect') var errorhandler = require('errorhandler') var notifier = require('node-notifier') var app = connect() // assumes NODE_ENV is set by the user if (process.env.NODE_ENV === 'development') { // only use in development app.use(errorhandler({ log: errorNotification })) } function errorNotification (err, str, req) { var title = 'Error in ' + req.method + ' ' + req.url notifier.notify({ title: title, message: str }) } ``` ## License [MIT](LICENSE) [coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/errorhandler/master [coveralls-url]: https://coveralls.io/r/expressjs/errorhandler?branch=master [npm-downloads-image]: https://badgen.net/npm/dm/errorhandler [npm-url]: https://npmjs.org/package/errorhandler [npm-version-image]: https://badgen.net/npm/v/errorhandler expressjs-errorhandler-f6bec9f/index.js000066400000000000000000000107261512005377500204730ustar00rootroot00000000000000/*! * errorhandler * Copyright(c) 2010 Sencha Inc. * Copyright(c) 2011 TJ Holowaychuk * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var accepts = require('accepts') var escapeHtml = require('escape-html') var fs = require('fs') var path = require('path') var util = require('util') /** * Module variables. * @private */ var DOUBLE_SPACE_REGEXP = /\x20{2}/g var NEW_LINE_REGEXP = /\n/g var STYLESHEET = fs.readFileSync(path.join(__dirname, '/public/style.css'), 'utf8') var TEMPLATE = fs.readFileSync(path.join(__dirname, '/public/error.html'), 'utf8') var inspect = util.inspect var toString = Object.prototype.toString /* istanbul ignore next */ var defer = typeof setImmediate === 'function' ? setImmediate : function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } /** * Error handler: * * Development error handler, providing stack traces * and error message responses for requests accepting text, html, * or json. * * Text: * * By default, and when _text/plain_ is accepted a simple stack trace * or error message will be returned. * * JSON: * * When _application/json_ is accepted, connect will respond with * an object in the form of `{ "error": error }`. * * HTML: * * When accepted connect will output a nice html stack trace. * * @return {Function} * @api public */ exports = module.exports = function errorHandler (options) { // get environment var env = process.env.NODE_ENV || 'development' // get options var opts = options || {} // get log option var log = opts.log === undefined ? env !== 'test' : opts.log if (typeof log !== 'function' && typeof log !== 'boolean') { throw new TypeError('option log must be function or boolean') } // default logging using console.error if (log === true) { log = logerror } return function errorHandler (err, req, res, next) { // respect err.statusCode if (err.statusCode) { res.statusCode = err.statusCode } // respect err.status if (err.status) { res.statusCode = err.status } // default status code to 500 if (res.statusCode < 400) { res.statusCode = 500 } // log the error var str = stringify(err) if (log) { defer(log, err, str, req, res) } // cannot actually respond if (res._header) { return req.socket.destroy() } // negotiate var accept = accepts(req) var type = accept.type('html', 'json', 'text') // Security header for content sniffing res.setHeader('X-Content-Type-Options', 'nosniff') // html if (type === 'html') { var isInspect = !err.stack && String(err) === toString.call(err) var errorHtml = !isInspect ? escapeHtmlBlock(str.split('\n', 1)[0] || 'Error') : 'Error' var stack = !isInspect ? String(str).split('\n').slice(1) : [str] var stackHtml = stack .map(function (v) { return '
  • ' + escapeHtmlBlock(v) + '
  • ' }) .join('') var body = TEMPLATE .replace('{style}', STYLESHEET) .replace('{stack}', stackHtml) .replace('{title}', escapeHtml(exports.title)) .replace('{statusCode}', res.statusCode) .replace(/\{error\}/g, errorHtml) res.setHeader('Content-Type', 'text/html; charset=utf-8') res.end(body) // json } else if (type === 'json') { var error = { message: err.message, stack: err.stack } for (var prop in err) error[prop] = err[prop] var json = JSON.stringify({ error: error }, null, 2) res.setHeader('Content-Type', 'application/json; charset=utf-8') res.end(json) // plain text } else { res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.end(str) } } } /** * Template title, framework authors may override this value. */ exports.title = 'Connect' /** * Escape a block of HTML, preserving whitespace. * @api private */ function escapeHtmlBlock (str) { return escapeHtml(str) .replace(DOUBLE_SPACE_REGEXP, '  ') .replace(NEW_LINE_REGEXP, '
    ') } /** * Stringify a value. * @api private */ function stringify (val) { var stack = val.stack if (stack) { return String(stack) } var str = String(val) return str === toString.call(val) ? inspect(val) : str } /** * Log error to console. * @api private */ function logerror (err, str) { console.error(str || err.stack) } expressjs-errorhandler-f6bec9f/package.json000066400000000000000000000022621512005377500213100ustar00rootroot00000000000000{ "name": "errorhandler", "description": "Development-only error handler middleware", "version": "1.5.2", "contributors": [ "Douglas Christopher Wilson ", "Jonathan Ong (http://jongleberry.com)" ], "license": "MIT", "repository": "expressjs/errorhandler", "funding": { "type": "opencollective", "url": "https://opencollective.com/express" }, "dependencies": { "accepts": "~1.3.8", "escape-html": "~1.0.3" }, "devDependencies": { "after": "0.8.2", "eslint": "8.34.0", "eslint-config-standard": "14.1.1", "eslint-plugin-import": "2.32.0", "eslint-plugin-markdown": "3.0.0", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "6.1.1", "mocha": "10.8.2", "nyc": "15.1.0", "supertest": "6.3.3" }, "files": [ "public/", "LICENSE", "index.js" ], "engines": { "node": ">= 0.8" }, "scripts": { "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=html --reporter=text npm test" } } expressjs-errorhandler-f6bec9f/public/000077500000000000000000000000001512005377500202765ustar00rootroot00000000000000expressjs-errorhandler-f6bec9f/public/error.html000066400000000000000000000004241512005377500223150ustar00rootroot00000000000000 {error}

    {title}

    {statusCode} {error}

      {stack}
    expressjs-errorhandler-f6bec9f/public/style.css000066400000000000000000000011321512005377500221450ustar00rootroot00000000000000* { margin: 0; padding: 0; outline: 0; } body { padding: 80px 100px; font: 13px "Helvetica Neue", "Lucida Grande", "Arial"; background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9)); background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9); background-repeat: no-repeat; color: #555; -webkit-font-smoothing: antialiased; } h1, h2 { font-size: 22px; color: #343434; } h1 em, h2 em { padding: 0 5px; font-weight: normal; } h1 { font-size: 60px; } h2 { margin-top: 10px; } ul li { list-style: none; } #stacktrace { margin-left: 60px; } expressjs-errorhandler-f6bec9f/test/000077500000000000000000000000001512005377500177775ustar00rootroot00000000000000expressjs-errorhandler-f6bec9f/test/.eslintrc.yml000066400000000000000000000000231512005377500224160ustar00rootroot00000000000000env: mocha: true expressjs-errorhandler-f6bec9f/test/test.js000066400000000000000000000261241512005377500213210ustar00rootroot00000000000000 process.env.NODE_ENV = 'test' var after = require('after') var assert = require('assert') var errorHandler = require('..') var http = require('http') var request = require('supertest') var util = require('util') describe('errorHandler()', function () { it('should set nosniff header', function (done) { var server = createServer(new Error('boom!')) request(server) .get('/') .expect('X-Content-Type-Options', 'nosniff') .expect(500, done) }) describe('status code', function () { describe('when non-error status code', function () { it('should set the status code to 500', function (done) { var server = createServer({ status: 200 }) request(server) .get('/') .expect(500, done) }) }) describe('when err.status exists', function () { it('should set res.statusCode', function (done) { var server = createServer({ status: 404 }) request(server) .get('/') .expect(404, done) }) }) describe('when err.statusCode exists', function () { it('should set res.statusCode', function (done) { var server = createServer({ statusCode: 404 }) request(server) .get('/') .expect(404, done) }) }) describe('when err.statusCode and err.status exist', function () { it('should prefer err.status', function (done) { var server = createServer({ statusCode: 400, status: 404 }) request(server) .get('/') .expect(404, done) }) }) }) describe('error value', function () { describe('when Error object', function () { it('should use "stack" property', function (done) { var error = new TypeError('boom!') var server = createServer(error) request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), done) }) }) describe('when string', function () { it('should pass-through string', function (done) { var server = createServer('boom!') request(server) .get('/') .set('Accept', 'text/plain') .expect(500, 'boom!', done) }) }) describe('when number', function () { it('should stringify number', function (done) { var server = createServer(42.1) request(server) .get('/') .set('Accept', 'text/plain') .expect(500, '42.1', done) }) }) describe('when object', function () { it('should use util.inspect', function (done) { var server = createServer({ hop: 'pop' }) request(server) .get('/') .set('Accept', 'text/plain') .expect(500, '{ hop: \'pop\' }', done) }) }) describe('with "toString" property', function () { it('should use "toString" value', function (done) { var server = createServer({ toString: function () { return 'boom!' } }) request(server) .get('/') .set('Accept', 'text/plain') .expect(500, 'boom!', done) }) }) }) describe('response content type', function () { var error var server before(function () { error = new Error('boom!') error.description = 'it went this way' server = createServer(error) }) describe('when "Accept: text/html"', function () { it('should return a html response', function (done) { request(server) .get('/') .set('Accept', 'text/html') .expect('Content-Type', /text\/html/) .expect(/Error: boom!<\/title>/) .expect(/<h2><em>500<\/em> Error: boom!<\/h2>/) .expect(/<li>    at/) .expect(500, done) }) it('should contain inspected object', function (done) { request(createServer({ foo: 'bar', fizz: 'buzz' })) .get('/') .set('Accept', 'text/html') .expect('Content-Type', /text\/html/) .expect(/<title>Error<\/title>/) .expect(/<h2><em>500<\/em> Error<\/h2>/) .expect(/<li>{ foo: 'bar', fizz: 'buzz' }<\/li>/) .expect(500, done) }) }) describe('when "Accept: application/json"', function () { it('should return a json response', function (done) { var body = { error: { message: 'boom!', description: 'it went this way', stack: error.stack.toString() } } request(server) .get('/') .set('Accept', 'application/json') .expect('Content-Type', /application\/json/) .expect(500, body, done) }) }) describe('when "Accept: text/plain"', function () { it('should return a plain text response', function (done) { request(server) .get('/') .set('Accept', 'text/plain') .expect('Content-Type', /text\/plain/) .expect(500, error.stack.toString(), done) }) }) describe('when "Accept: x-unknown"', function () { it('should return a plain text response', function (done) { request(server) .get('/') .set('Accept', 'x-unknown') .expect('Content-Type', /text\/plain/) .expect(500, error.stack.toString(), done) }) }) }) describe('headers sent', function () { var server before(function () { var _errorHandler = errorHandler() server = http.createServer(function (req, res) { res.end('0') process.nextTick(function () { _errorHandler(new Error('boom!'), req, res, function (error) { process.nextTick(function () { throw error }) }) }) }) }) it('should not die', function (done) { request(server) .get('/') .expect(200, done) }) }) describe('console', function () { var _consoleerror before(function () { _consoleerror = console.error process.env.NODE_ENV = '' }) afterEach(function () { console.error = _consoleerror process.env.NODE_ENV = 'test' }) it('should output error', function (done) { var cb = after(2, done) var error = new Error('boom!') var server = createServer(error) console.error = function () { var log = util.format.apply(null, arguments) if (log !== error.stack.toString()) { return _consoleerror.apply(this, arguments) } cb() } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), cb) }) }) }) describe('errorHandler(options)', function () { describe('log', function () { it('should reject a string', function () { assert.throws(errorHandler.bind(null, { log: 'yes, please' }), /option log must be/) }) describe('when "undefined"', function () { var _consoleerror before(function () { _consoleerror = console.error }) afterEach(function () { console.error = _consoleerror }) describe('when NODE_ENV == test', function () { alterEnvironment('NODE_ENV', 'test') it('should produce no output', function (done) { var error = new Error('boom!') var server = createServer(error) console.error = function () { var log = util.format.apply(null, arguments) if (log !== error.stack.toString()) { return _consoleerror.apply(this, arguments) } done(new Error('console.error written to')) } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), done) }) }) describe('when NODE_ENV != test', function () { alterEnvironment('NODE_ENV', '') it('should write to console', function (done) { var cb = after(2, done) var error = new Error('boom!') var server = createServer(error) console.error = function () { var log = util.format.apply(null, arguments) if (log !== error.stack.toString()) { return _consoleerror.apply(this, arguments) } cb() } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), cb) }) }) }) describe('when "true"', function () { var _consoleerror before(function () { _consoleerror = console.error }) afterEach(function () { console.error = _consoleerror }) it('should write to console', function (done) { var cb = after(2, done) var error = new Error('boom!') var server = createServer(error, { log: true }) console.error = function () { var log = util.format.apply(null, arguments) if (log !== error.stack.toString()) { return _consoleerror.apply(this, arguments) } cb() } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), cb) }) }) describe('when "false"', function () { var _consoleerror alterEnvironment('NODE_ENV', '') before(function () { _consoleerror = console.error }) afterEach(function () { console.error = _consoleerror }) it('should not write to console', function (done) { var error = new Error('boom!') var server = createServer(error, { log: false }) console.error = function () { var log = util.format.apply(null, arguments) if (log !== error.stack.toString()) { return _consoleerror.apply(this, arguments) } done(new Error('console.error written to')) } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), done) }) }) describe('when a function', function () { it('should call function', function (done) { var cb = after(2, done) var error = new Error('boom!') var server = createServer(error, { log: log }) function log (err, str, req, res) { assert.strictEqual(err, error) assert.strictEqual(str, error.stack.toString()) assert.strictEqual(req.url, '/') assert.strictEqual(res.statusCode, 500) cb() } request(server) .get('/') .set('Accept', 'text/plain') .expect(500, error.stack.toString(), cb) }) }) }) }) function createServer (error, options) { var _errorHandler = errorHandler(options) return http.createServer(function (req, res) { _errorHandler(error, req, res, function (err) { res.statusCode = err ? 500 : 404 res.end(err ? 'Critical: ' + err.stack : 'oops') }) }) } function alterEnvironment (key, value) { var prev before(function () { prev = process.env[key] process.env[key] = value }) after(function () { process.env[key] = prev }) } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������