diff --git a/types/errorhandler/errorhandler-tests.ts b/types/errorhandler/errorhandler-tests.ts index 3f8ada3372..a4e1833363 100644 --- a/types/errorhandler/errorhandler-tests.ts +++ b/types/errorhandler/errorhandler-tests.ts @@ -1,16 +1,35 @@ import express = require('express'); import errorhandler = require('errorhandler'); +import notifier = require('node-notifier'); +import errorHandler = require('errorhandler'); -var app = express(); +const app = express(); -app.use(errorhandler()); +const errorNotification: errorhandler.LoggingCallback = (err, str, req) => { + const title = `Error in ${req.method} ${req.url}`; + notifier.notify({ + title, + message: str, + }); +}; + +if (process.env.NODE_ENV === 'development') { + app.use(errorhandler()); +} app.use(errorhandler({ log: true })); +app.use(errorhandler({ log: false })); +app.use(errorhandler({ log: errorNotification })); -app.use(errorhandler({ log: (err, str, req, res) => { - const { message, name, stack } = err; - const messageIsStr = message === str; +app.use( + errorhandler({ + log: (err, str, req, res) => { + const { message, name, stack } = err; + const messageIsStr = message === str; + const requestWasFresh = req && req.fresh; + const responseContentType = res && res.contentType; + }, + }), +); - const requestWasFresh = req && req.fresh; - const responseContentType = res && res.contentType -}})) +errorHandler.title; // $ExpectType string diff --git a/types/errorhandler/index.d.ts b/types/errorhandler/index.d.ts index 71f0f3db21..b58bf99b6d 100644 --- a/types/errorhandler/index.d.ts +++ b/types/errorhandler/index.d.ts @@ -1,11 +1,14 @@ -// Type definitions for errorhandler +// Type definitions for errorhandler 1.5 // Project: https://github.com/expressjs/errorhandler // Definitions by: Santi Albo +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 -import * as express from 'express'; +import express = require('express'); +/** + * Create new middleware to handle errors and respond with content negotiation. + */ declare function errorHandler(options?: errorHandler.Options): express.ErrorRequestHandler; declare namespace errorHandler { @@ -15,6 +18,7 @@ declare namespace errorHandler { interface Options { /** + * Provide a function to be called with the error and a string representation of the erro * Defaults to true. * * Possible values: @@ -24,6 +28,11 @@ declare namespace errorHandler { */ log: boolean | LoggingCallback; } + + /** + * Template title, framework authors may override this value. + */ + const title: string; } export = errorHandler; diff --git a/types/errorhandler/tsconfig.json b/types/errorhandler/tsconfig.json index dc08f31d21..2e317e919a 100644 --- a/types/errorhandler/tsconfig.json +++ b/types/errorhandler/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -20,4 +20,4 @@ "index.d.ts", "errorhandler-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/errorhandler/tslint.json b/types/errorhandler/tslint.json index 3d59f55fda..3db14f85ea 100644 --- a/types/errorhandler/tslint.json +++ b/types/errorhandler/tslint.json @@ -1,80 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "npm-naming": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} +{ "extends": "dtslint/dt.json" }