@emoyly/problem 4.1.10 → 4.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/{dist/defaults → defaults}/4xx.d.ts +147 -147
  2. package/{dist/defaults → defaults}/4xx.js +151 -151
  3. package/{dist/defaults → defaults}/5xx.d.ts +57 -57
  4. package/{dist/defaults → defaults}/5xx.js +61 -61
  5. package/{dist/defaults → defaults}/aws.d.ts +12 -12
  6. package/{dist/defaults → defaults}/aws.js +16 -16
  7. package/{dist/defaults → defaults}/cloudflare.d.ts +47 -47
  8. package/{dist/defaults → defaults}/cloudflare.js +52 -52
  9. package/{dist/defaults → defaults}/iis.d.ts +17 -17
  10. package/{dist/defaults → defaults}/iis.js +21 -21
  11. package/{dist/defaults → defaults}/index.d.ts +7 -7
  12. package/{dist/defaults → defaults}/index.js +17 -17
  13. package/{dist/defaults → defaults}/nginx.d.ts +32 -32
  14. package/{dist/defaults → defaults}/nginx.js +36 -36
  15. package/{dist/defaults → defaults}/others.d.ts +37 -37
  16. package/{dist/defaults → defaults}/others.js +40 -40
  17. package/{dist/index.d.ts → index.d.ts} +4 -4
  18. package/{dist/index.js → index.js} +34 -34
  19. package/{dist/middleware → middleware}/axios.d.ts +13 -13
  20. package/{dist/middleware → middleware}/axios.js +36 -36
  21. package/{dist/middleware → middleware}/base.d.ts +24 -24
  22. package/{dist/middleware → middleware}/base.js +49 -49
  23. package/{dist/middleware → middleware}/express.d.ts +19 -19
  24. package/{dist/middleware → middleware}/express.js +57 -57
  25. package/package.json +7 -19
  26. package/{dist/parsers → parsers}/axios.d.ts +3 -3
  27. package/{dist/parsers → parsers}/axios.js +39 -39
  28. package/{dist/parsers → parsers}/http.d.ts +3 -3
  29. package/{dist/parsers → parsers}/http.js +15 -15
  30. package/{dist/parsers → parsers}/jsonwebtoken.d.ts +3 -3
  31. package/{dist/parsers → parsers}/jsonwebtoken.js +96 -96
  32. package/{dist/parsers → parsers}/mikroorm.d.ts +3 -3
  33. package/{dist/parsers → parsers}/mikroorm.js +15 -15
  34. package/{dist/parsers → parsers}/tsoa.d.ts +3 -3
  35. package/{dist/parsers → parsers}/tsoa.js +17 -17
  36. package/{dist/problem.d.ts → problem.d.ts} +13 -13
  37. package/{dist/problem.js → problem.js} +50 -50
  38. package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +793 -793
  39. package/{dist/typings → typings}/events.d.ts +2 -2
  40. package/{dist/typings → typings}/events.js +2 -2
  41. package/{dist/typings → typings}/index.d.ts +5 -5
  42. package/{dist/typings → typings}/index.js +17 -17
  43. package/{dist/typings → typings}/middleware.d.ts +9 -9
  44. package/{dist/typings → typings}/middleware.js +2 -2
  45. package/{dist/typings → typings}/misc.d.ts +3 -3
  46. package/{dist/typings → typings}/misc.js +2 -2
  47. package/{dist/typings → typings}/parser.d.ts +9 -9
  48. package/{dist/typings → typings}/parser.js +2 -2
  49. package/{dist/typings → typings}/problem.d.ts +23 -23
  50. package/{dist/typings → typings}/problem.js +12 -12
  51. package/{dist/util → util}/events.d.ts +16 -16
  52. package/{dist/util → util}/events.js +29 -29
  53. package/{dist/util → util}/getProblems.d.ts +5 -5
  54. package/{dist/util → util}/getProblems.js +45 -45
  55. package/{dist/util → util}/version.d.ts +3 -3
  56. package/{dist/util → util}/version.js +20 -20
  57. package/dist/LICENSE +0 -21
  58. package/dist/README.md +0 -59
  59. package/dist/SECURITY.md +0 -12
  60. package/dist/package.json +0 -45
  61. package/dist/yarn.lock +0 -2076
@@ -1,19 +1,19 @@
1
- import type { NextFunction, Request, Response } from 'express';
2
- import type { PartialMiddlewareOptions } from '../typings/middleware';
3
- import { MiddlewareBase } from './base';
4
- export declare class ExpressMiddleware extends MiddlewareBase {
5
- name: string;
6
- middleware: (error: any, req: Request, res: Response, next: NextFunction) => void;
7
- /**
8
- * This function applies the middleware to your Express application. Put this at the very end of your middleware/routes.
9
- * If you want to also handle 404 errors, check out the notFound middleware function.
10
- * @example app.use(middleware.use())
11
- */
12
- use: () => (error: any, req: Request, res: Response, next: NextFunction) => void;
13
- constructor(options?: PartialMiddlewareOptions);
14
- /**
15
- * Put this right before the middleware.use() to catch all 404 errors and respond with a Problem instead of the default Express response
16
- * @example app.use(middleware.notFound)
17
- */
18
- notFound: (req: Request, res: Response, next: NextFunction) => void;
19
- }
1
+ import type { NextFunction, Request, Response } from 'express';
2
+ import type { PartialMiddlewareOptions } from '../typings/middleware';
3
+ import { MiddlewareBase } from './base';
4
+ export declare class ExpressMiddleware extends MiddlewareBase {
5
+ name: string;
6
+ middleware: (error: any, req: Request, res: Response, next: NextFunction) => void;
7
+ /**
8
+ * This function applies the middleware to your Express application. Put this at the very end of your middleware/routes.
9
+ * If you want to also handle 404 errors, check out the notFound middleware function.
10
+ * @example app.use(middleware.use())
11
+ */
12
+ use: () => (error: any, req: Request, res: Response, next: NextFunction) => void;
13
+ constructor(options?: PartialMiddlewareOptions);
14
+ /**
15
+ * Put this right before the middleware.use() to catch all 404 errors and respond with a Problem instead of the default Express response
16
+ * @example app.use(middleware.notFound)
17
+ */
18
+ notFound: (req: Request, res: Response, next: NextFunction) => void;
19
+ }
@@ -1,57 +1,57 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ExpressMiddleware = void 0;
7
- const base_1 = require("./base");
8
- const problem_1 = require("../problem");
9
- const defaults_1 = require("../defaults");
10
- const events_1 = __importDefault(require("../util/events"));
11
- class ExpressMiddleware extends base_1.MiddlewareBase {
12
- constructor(options) {
13
- super({
14
- 'parsers': []
15
- }, options);
16
- this.name = 'express';
17
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
- this.middleware = (error, req, res, next) => {
19
- this.parse(error)
20
- .then(problems => {
21
- var _a, _b;
22
- for (const problem of problems) {
23
- if (problem.instance === '/unknown') {
24
- problem.instance = req.originalUrl;
25
- }
26
- }
27
- events_1.default.emit(problems);
28
- res
29
- .contentType('application/problem+json')
30
- .status((_b = (_a = problems[0]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500)
31
- .json(problems.map(val => val.toObject()));
32
- })
33
- .catch(err => {
34
- res
35
- .contentType('application/problem+json')
36
- .status(500)
37
- .json([new problem_1.Problem(Object.assign(Object.assign({}, defaults_1.otherErrors.unknown), { 'instance': req.originalUrl, 'status': 500 })).toObject()]);
38
- throw err;
39
- });
40
- };
41
- /**
42
- * This function applies the middleware to your Express application. Put this at the very end of your middleware/routes.
43
- * If you want to also handle 404 errors, check out the notFound middleware function.
44
- * @example app.use(middleware.use())
45
- */
46
- this.use = () => this.middleware;
47
- /**
48
- * Put this right before the middleware.use() to catch all 404 errors and respond with a Problem instead of the default Express response
49
- * @example app.use(middleware.notFound)
50
- */
51
- this.notFound = (req, res, next) => {
52
- const error = new problem_1.Problem(Object.assign(Object.assign({}, defaults_1.codes4xx[404]), { 'instance': req.originalUrl, 'detail': `No API endpoints exist on ${req.url} for request method ${req.method}` }));
53
- return next(error);
54
- };
55
- }
56
- }
57
- exports.ExpressMiddleware = ExpressMiddleware;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ExpressMiddleware = void 0;
7
+ const base_1 = require("./base");
8
+ const problem_1 = require("../problem");
9
+ const defaults_1 = require("../defaults");
10
+ const events_1 = __importDefault(require("../util/events"));
11
+ class ExpressMiddleware extends base_1.MiddlewareBase {
12
+ constructor(options) {
13
+ super({
14
+ 'parsers': []
15
+ }, options);
16
+ this.name = 'express';
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ this.middleware = (error, req, res, next) => {
19
+ this.parse(error)
20
+ .then(problems => {
21
+ var _a, _b;
22
+ for (const problem of problems) {
23
+ if (problem.instance === '/unknown') {
24
+ problem.instance = req.originalUrl;
25
+ }
26
+ }
27
+ events_1.default.emit(problems);
28
+ res
29
+ .contentType('application/problem+json')
30
+ .status((_b = (_a = problems[0]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500)
31
+ .json(problems.map(val => val.toObject()));
32
+ })
33
+ .catch(err => {
34
+ res
35
+ .contentType('application/problem+json')
36
+ .status(500)
37
+ .json([new problem_1.Problem(Object.assign(Object.assign({}, defaults_1.otherErrors.unknown), { 'instance': req.originalUrl, 'status': 500 })).toObject()]);
38
+ throw err;
39
+ });
40
+ };
41
+ /**
42
+ * This function applies the middleware to your Express application. Put this at the very end of your middleware/routes.
43
+ * If you want to also handle 404 errors, check out the notFound middleware function.
44
+ * @example app.use(middleware.use())
45
+ */
46
+ this.use = () => this.middleware;
47
+ /**
48
+ * Put this right before the middleware.use() to catch all 404 errors and respond with a Problem instead of the default Express response
49
+ * @example app.use(middleware.notFound)
50
+ */
51
+ this.notFound = (req, res, next) => {
52
+ const error = new problem_1.Problem(Object.assign(Object.assign({}, defaults_1.codes4xx[404]), { 'instance': req.originalUrl, 'detail': `No API endpoints exist on ${req.url} for request method ${req.method}` }));
53
+ return next(error);
54
+ };
55
+ }
56
+ }
57
+ exports.ExpressMiddleware = ExpressMiddleware;
package/package.json CHANGED
@@ -1,19 +1,12 @@
1
1
  {
2
2
  "name": "@emoyly/problem",
3
- "version": "4.1.10",
3
+ "version": "4.1.11",
4
4
  "description": "A simple error library based around the RFC-7807 standard with optional support for Sentry.io and Express",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
7
  "repository": "https://github.com/emoyly/problem",
8
8
  "author": "Emil Petersen <emoyly@gmail.com>",
9
9
  "license": "MIT",
10
- "scripts": {
11
- "build": "tsc",
12
- "lint": "eslint src"
13
- },
14
- "publishConfig": {
15
- "registry": "https://registry.npmjs.org"
16
- },
17
10
  "devDependencies": {
18
11
  "@mikro-orm/core": "^4.5.9",
19
12
  "@types/express": "^4.17.11",
@@ -44,12 +37,7 @@
44
37
  }
45
38
  },
46
39
  "packageManager": "yarn@3.2.0",
47
- "exports": {
48
- ".": "./dist/"
49
- },
50
- "files": [
51
- "dist/**/*",
52
- "SECURITY.MD",
53
- "README.md"
54
- ]
55
- }
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org"
42
+ }
43
+ }
@@ -1,3 +1,3 @@
1
- import { Parser } from '../typings/parser';
2
- declare const parse: Parser;
3
- export default parse;
1
+ import { Parser } from '../typings/parser';
2
+ declare const parse: Parser;
3
+ export default parse;
@@ -1,39 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const others_1 = require("../defaults/others");
4
- const problem_1 = require("../problem");
5
- const getProblems_1 = require("../util/getProblems");
6
- const http_1 = require("./http");
7
- const parse = (input) => {
8
- var _a, _b, _c, _d, _e, _f;
9
- const request = input.request;
10
- if ((_a = input === null || input === void 0 ? void 0 : input.response) === null || _a === void 0 ? void 0 : _a.data) {
11
- const problems = getProblems_1.getProblems((_b = input === null || input === void 0 ? void 0 : input.response) === null || _b === void 0 ? void 0 : _b.data);
12
- if (problems)
13
- return problems;
14
- }
15
- if (input === null || input === void 0 ? void 0 : input.response) {
16
- const url = `${(_c = input.config) === null || _c === void 0 ? void 0 : _c.baseURL}${(_d = input.config) === null || _d === void 0 ? void 0 : _d.url}`;
17
- const problem = http_1.parseHTTPError({
18
- 'body': input.response.data,
19
- 'headers': input.response.headers,
20
- 'statusCode': input.response.status,
21
- url
22
- });
23
- if (problem)
24
- return [problem];
25
- }
26
- if (request) {
27
- const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
28
- const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
29
- if (isBrowser && request instanceof XMLHttpRequest) {
30
- return [new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.networkError), { 'instance': (_e = input === null || input === void 0 ? void 0 : input.config) === null || _e === void 0 ? void 0 : _e.url }))];
31
- }
32
- // Probably a ClientRequest
33
- if (isNode && 'pipe' in request && 'destroy' in request) {
34
- return [new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.networkError), { 'instance': (_f = input === null || input === void 0 ? void 0 : input.config) === null || _f === void 0 ? void 0 : _f.url }))];
35
- }
36
- }
37
- return [];
38
- };
39
- exports.default = parse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const others_1 = require("../defaults/others");
4
+ const problem_1 = require("../problem");
5
+ const getProblems_1 = require("../util/getProblems");
6
+ const http_1 = require("./http");
7
+ const parse = (input) => {
8
+ var _a, _b, _c, _d, _e, _f;
9
+ const request = input.request;
10
+ if ((_a = input === null || input === void 0 ? void 0 : input.response) === null || _a === void 0 ? void 0 : _a.data) {
11
+ const problems = getProblems_1.getProblems((_b = input === null || input === void 0 ? void 0 : input.response) === null || _b === void 0 ? void 0 : _b.data);
12
+ if (problems)
13
+ return problems;
14
+ }
15
+ if (input === null || input === void 0 ? void 0 : input.response) {
16
+ const url = `${(_c = input.config) === null || _c === void 0 ? void 0 : _c.baseURL}${(_d = input.config) === null || _d === void 0 ? void 0 : _d.url}`;
17
+ const problem = http_1.parseHTTPError({
18
+ 'body': input.response.data,
19
+ 'headers': input.response.headers,
20
+ 'statusCode': input.response.status,
21
+ url
22
+ });
23
+ if (problem)
24
+ return [problem];
25
+ }
26
+ if (request) {
27
+ const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
28
+ const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
29
+ if (isBrowser && request instanceof XMLHttpRequest) {
30
+ return [new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.networkError), { 'instance': (_e = input === null || input === void 0 ? void 0 : input.config) === null || _e === void 0 ? void 0 : _e.url }))];
31
+ }
32
+ // Probably a ClientRequest
33
+ if (isNode && 'pipe' in request && 'destroy' in request) {
34
+ return [new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.networkError), { 'instance': (_f = input === null || input === void 0 ? void 0 : input.config) === null || _f === void 0 ? void 0 : _f.url }))];
35
+ }
36
+ }
37
+ return [];
38
+ };
39
+ exports.default = parse;
@@ -1,3 +1,3 @@
1
- import { Problem } from '../problem';
2
- import type { HTTPErrorDetails } from '../typings/parser';
3
- export declare function parseHTTPError(input: HTTPErrorDetails): Problem | void;
1
+ import { Problem } from '../problem';
2
+ import type { HTTPErrorDetails } from '../typings/parser';
3
+ export declare function parseHTTPError(input: HTTPErrorDetails): Problem | void;
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseHTTPError = void 0;
4
- const defaults_1 = require("../defaults");
5
- const problem_1 = require("../problem");
6
- const codes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults_1.codes4xx), defaults_1.codes5xx), defaults_1.codesAws), defaults_1.codesCloudflare), defaults_1.codesIis), defaults_1.codesNginx);
7
- function parseHTTPError(input) {
8
- var _a;
9
- if (input.statusCode) {
10
- const found = (_a = Object.entries(codes).find(([key]) => { var _a; return key === ((_a = input.statusCode) === null || _a === void 0 ? void 0 : _a.toString()); })) === null || _a === void 0 ? void 0 : _a[1];
11
- if (found)
12
- return new problem_1.Problem(Object.assign({}, found));
13
- }
14
- }
15
- exports.parseHTTPError = parseHTTPError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseHTTPError = void 0;
4
+ const defaults_1 = require("../defaults");
5
+ const problem_1 = require("../problem");
6
+ const codes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults_1.codes4xx), defaults_1.codes5xx), defaults_1.codesAws), defaults_1.codesCloudflare), defaults_1.codesIis), defaults_1.codesNginx);
7
+ function parseHTTPError(input) {
8
+ var _a;
9
+ if (input.statusCode) {
10
+ const found = (_a = Object.entries(codes).find(([key]) => { var _a; return key === ((_a = input.statusCode) === null || _a === void 0 ? void 0 : _a.toString()); })) === null || _a === void 0 ? void 0 : _a[1];
11
+ if (found)
12
+ return new problem_1.Problem(Object.assign({}, found));
13
+ }
14
+ }
15
+ exports.parseHTTPError = parseHTTPError;
@@ -1,3 +1,3 @@
1
- import { Parser } from '../typings/parser';
2
- declare const parse: Parser;
3
- export default parse;
1
+ import { Parser } from '../typings/parser';
2
+ declare const parse: Parser;
3
+ export default parse;
@@ -1,96 +1,96 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const problem_1 = require("../problem");
4
- const jsonwebtoken_1 = require("jsonwebtoken");
5
- const errorMap = [
6
- {
7
- 'search': 'invalid token',
8
- 'result': {
9
- 'type': '/errors/jsonwebtoken/invalidtoken',
10
- 'status': 400,
11
- 'title': 'Invalid JSON Web Token',
12
- }
13
- },
14
- {
15
- 'search': 'jwt malformed',
16
- 'result': {
17
- 'type': '/errors/jsonwebtoken/malformed',
18
- 'status': 400,
19
- 'title': 'Malformed JSON Web Token',
20
- }
21
- },
22
- {
23
- 'search': 'jwt signature is required',
24
- 'result': {
25
- 'type': '/errors/jsonwebtoken/signaturerequired',
26
- 'status': 400,
27
- 'title': 'JSON Web Token is missing, but required',
28
- }
29
- },
30
- {
31
- 'search': 'invalid signature',
32
- 'result': {
33
- 'type': '/errors/jsonwebtoken/invalidsignature',
34
- 'status': 400,
35
- 'title': 'The JSON Web Token signature is invalid',
36
- }
37
- },
38
- {
39
- 'search': /^(jwt audience invalid\. expected:)/,
40
- 'result': {
41
- 'type': '/errors/jsonwebtoken/invalidaud',
42
- 'status': 400,
43
- 'title': 'The JSON Web Token audience is invalid',
44
- }
45
- },
46
- {
47
- 'search': /^(jwt issuer invalid\. expected:)/,
48
- 'result': {
49
- 'type': '/errors/jsonwebtoken/invalidiss',
50
- 'status': 400,
51
- 'title': 'The JSON Web Token issuer is invalid',
52
- }
53
- },
54
- {
55
- 'search': /^(jwt id invalid\. expected:)/,
56
- 'result': {
57
- 'type': '/errors/jsonwebtoken/invalidid',
58
- 'status': 400,
59
- 'title': 'The JSON Web Token id is invalid',
60
- }
61
- },
62
- {
63
- 'search': /^(jwt subject invalid\. expected:)/,
64
- 'result': {
65
- 'type': '/errors/jsonwebtoken/invalidsubject',
66
- 'status': 400,
67
- 'title': 'The JSON Web Token subject is invalid',
68
- }
69
- }
70
- ];
71
- const parse = (input) => {
72
- if (input instanceof jsonwebtoken_1.JsonWebTokenError && input.name === 'JsonWebTokenError') {
73
- const found = errorMap.find(val => typeof val.search === 'string' ? val.search === input.message : val.search.test(input.message));
74
- if (found) {
75
- return [new problem_1.Problem(found.result)];
76
- }
77
- }
78
- else if (input instanceof jsonwebtoken_1.TokenExpiredError && input.name === 'TokenExpiredError') {
79
- return [new problem_1.Problem({
80
- 'title': 'The JSON Web Token has expired',
81
- 'type': '/errors/jsonwebtoken/tokenexpired',
82
- 'detail': `The JSON Web Token expired at ${input.expiredAt}`,
83
- 'status': 400,
84
- })];
85
- }
86
- else if (input instanceof jsonwebtoken_1.NotBeforeError && input.name === 'NotBeforeError') {
87
- return [new problem_1.Problem({
88
- 'title': 'The JSON Web Token is not valid yet',
89
- 'type': '/errors/jsonwebtoken/notbefore',
90
- 'detail': `The JSON Web Token is not valid before ${input.date}`,
91
- 'status': 400,
92
- })];
93
- }
94
- return [];
95
- };
96
- exports.default = parse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const problem_1 = require("../problem");
4
+ const jsonwebtoken_1 = require("jsonwebtoken");
5
+ const errorMap = [
6
+ {
7
+ 'search': 'invalid token',
8
+ 'result': {
9
+ 'type': '/errors/jsonwebtoken/invalidtoken',
10
+ 'status': 400,
11
+ 'title': 'Invalid JSON Web Token',
12
+ }
13
+ },
14
+ {
15
+ 'search': 'jwt malformed',
16
+ 'result': {
17
+ 'type': '/errors/jsonwebtoken/malformed',
18
+ 'status': 400,
19
+ 'title': 'Malformed JSON Web Token',
20
+ }
21
+ },
22
+ {
23
+ 'search': 'jwt signature is required',
24
+ 'result': {
25
+ 'type': '/errors/jsonwebtoken/signaturerequired',
26
+ 'status': 400,
27
+ 'title': 'JSON Web Token is missing, but required',
28
+ }
29
+ },
30
+ {
31
+ 'search': 'invalid signature',
32
+ 'result': {
33
+ 'type': '/errors/jsonwebtoken/invalidsignature',
34
+ 'status': 400,
35
+ 'title': 'The JSON Web Token signature is invalid',
36
+ }
37
+ },
38
+ {
39
+ 'search': /^(jwt audience invalid\. expected:)/,
40
+ 'result': {
41
+ 'type': '/errors/jsonwebtoken/invalidaud',
42
+ 'status': 400,
43
+ 'title': 'The JSON Web Token audience is invalid',
44
+ }
45
+ },
46
+ {
47
+ 'search': /^(jwt issuer invalid\. expected:)/,
48
+ 'result': {
49
+ 'type': '/errors/jsonwebtoken/invalidiss',
50
+ 'status': 400,
51
+ 'title': 'The JSON Web Token issuer is invalid',
52
+ }
53
+ },
54
+ {
55
+ 'search': /^(jwt id invalid\. expected:)/,
56
+ 'result': {
57
+ 'type': '/errors/jsonwebtoken/invalidid',
58
+ 'status': 400,
59
+ 'title': 'The JSON Web Token id is invalid',
60
+ }
61
+ },
62
+ {
63
+ 'search': /^(jwt subject invalid\. expected:)/,
64
+ 'result': {
65
+ 'type': '/errors/jsonwebtoken/invalidsubject',
66
+ 'status': 400,
67
+ 'title': 'The JSON Web Token subject is invalid',
68
+ }
69
+ }
70
+ ];
71
+ const parse = (input) => {
72
+ if (input instanceof jsonwebtoken_1.JsonWebTokenError && input.name === 'JsonWebTokenError') {
73
+ const found = errorMap.find(val => typeof val.search === 'string' ? val.search === input.message : val.search.test(input.message));
74
+ if (found) {
75
+ return [new problem_1.Problem(found.result)];
76
+ }
77
+ }
78
+ else if (input instanceof jsonwebtoken_1.TokenExpiredError && input.name === 'TokenExpiredError') {
79
+ return [new problem_1.Problem({
80
+ 'title': 'The JSON Web Token has expired',
81
+ 'type': '/errors/jsonwebtoken/tokenexpired',
82
+ 'detail': `The JSON Web Token expired at ${input.expiredAt}`,
83
+ 'status': 400,
84
+ })];
85
+ }
86
+ else if (input instanceof jsonwebtoken_1.NotBeforeError && input.name === 'NotBeforeError') {
87
+ return [new problem_1.Problem({
88
+ 'title': 'The JSON Web Token is not valid yet',
89
+ 'type': '/errors/jsonwebtoken/notbefore',
90
+ 'detail': `The JSON Web Token is not valid before ${input.date}`,
91
+ 'status': 400,
92
+ })];
93
+ }
94
+ return [];
95
+ };
96
+ exports.default = parse;
@@ -1,3 +1,3 @@
1
- import { Parser } from '../typings/parser';
2
- declare const parse: Parser;
3
- export default parse;
1
+ import { Parser } from '../typings/parser';
2
+ declare const parse: Parser;
3
+ export default parse;
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const problem_1 = require("../problem");
4
- const _4xx_1 = require("../defaults/4xx");
5
- const core_1 = require("@mikro-orm/core");
6
- // TODO: Make this less bad
7
- const parse = (input) => {
8
- if (!(input instanceof core_1.NotFoundError)) {
9
- return [];
10
- }
11
- return [
12
- new problem_1.Problem(_4xx_1.statusCodes['404'])
13
- ];
14
- };
15
- exports.default = parse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const problem_1 = require("../problem");
4
+ const _4xx_1 = require("../defaults/4xx");
5
+ const core_1 = require("@mikro-orm/core");
6
+ // TODO: Make this less bad
7
+ const parse = (input) => {
8
+ if (!(input instanceof core_1.NotFoundError)) {
9
+ return [];
10
+ }
11
+ return [
12
+ new problem_1.Problem(_4xx_1.statusCodes['404'])
13
+ ];
14
+ };
15
+ exports.default = parse;
@@ -1,3 +1,3 @@
1
- import { Parser } from '../typings/parser';
2
- declare const parse: Parser;
3
- export default parse;
1
+ import { Parser } from '../typings/parser';
2
+ declare const parse: Parser;
3
+ export default parse;
@@ -1,17 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tsoa_1 = require("tsoa");
4
- const problem_1 = require("../problem");
5
- const others_1 = require("../defaults/others");
6
- const parse = (input) => {
7
- if (!(input instanceof tsoa_1.ValidateError)) {
8
- return [];
9
- }
10
- // TODO: Give actual useful responses instead of this shit
11
- return [
12
- new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.inputValidationError), { 'detail': input.message, 'status': input.status, 'data': {
13
- 'fields': input.fields,
14
- } }))
15
- ];
16
- };
17
- exports.default = parse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tsoa_1 = require("tsoa");
4
+ const problem_1 = require("../problem");
5
+ const others_1 = require("../defaults/others");
6
+ const parse = (input) => {
7
+ if (!(input instanceof tsoa_1.ValidateError)) {
8
+ return [];
9
+ }
10
+ // TODO: Give actual useful responses instead of this shit
11
+ return [
12
+ new problem_1.Problem(Object.assign(Object.assign({}, others_1.otherErrors.inputValidationError), { 'detail': input.message, 'status': input.status, 'data': {
13
+ 'fields': input.fields,
14
+ } }))
15
+ ];
16
+ };
17
+ exports.default = parse;
@@ -1,13 +1,13 @@
1
- import { IProblem, ProblemOpts, JsonProblem } from './typings/problem';
2
- export declare class Problem extends Error implements IProblem {
3
- type: string;
4
- title: string;
5
- status: number;
6
- detail: string;
7
- instance: string;
8
- errorObject?: unknown;
9
- __problemVersion: string;
10
- data: any;
11
- constructor({ type, title, status, detail, instance, stack, errorObject, data }: ProblemOpts);
12
- toObject: () => JsonProblem;
13
- }
1
+ import { IProblem, ProblemOpts, JsonProblem } from './typings/problem';
2
+ export declare class Problem extends Error implements IProblem {
3
+ type: string;
4
+ title: string;
5
+ status: number;
6
+ detail: string;
7
+ instance: string;
8
+ errorObject?: unknown;
9
+ __problemVersion: string;
10
+ data: any;
11
+ constructor({ type, title, status, detail, instance, stack, errorObject, data }: ProblemOpts);
12
+ toObject: () => JsonProblem;
13
+ }