diff --git a/types/express-jwt/express-jwt-tests.ts b/types/express-jwt/express-jwt-tests.ts
index 190c85ce4b..798818b728 100644
--- a/types/express-jwt/express-jwt-tests.ts
+++ b/types/express-jwt/express-jwt-tests.ts
@@ -17,4 +17,15 @@ var jwtCheck = jwt({
secret: 'shhhhhhared-secret'
});
jwtCheck.unless = unless;
-app.use(jwtCheck.unless({ path: '/api/login' }));
\ No newline at end of file
+app.use(jwtCheck.unless({ path: '/api/login' }));
+
+app.use(function (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
+ if (err) {
+ if (err instanceof jwt.UnauthorizedError) {
+ res.status(err.status);
+ res.end();
+ }
+ } else {
+ next(err);
+ }
+});
\ No newline at end of file
diff --git a/types/express-jwt/index.d.ts b/types/express-jwt/index.d.ts
index d75dfa9adf..ec7aeb64f7 100644
--- a/types/express-jwt/index.d.ts
+++ b/types/express-jwt/index.d.ts
@@ -1,6 +1,6 @@
// Type definitions for express-jwt
// Project: https://www.npmjs.org/package/express-jwt
-// Definitions by: Wonshik Kim , Kacper Polak
+// Definitions by: Wonshik Kim , Kacper Polak , Sl1MBoy
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import express = require('express');
@@ -36,6 +36,14 @@ declare namespace jwt {
export interface RequestHandler extends express.RequestHandler {
unless: typeof unless;
}
+
+ export class UnauthorizedError extends Error {
+ name: string;
+ message: string;
+ code: string;
+ status: number;
+ inner: Error
+ }
}
declare global {
namespace Express {