@emoyly/problem 5.0.8 → 6.0.0
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.
- package/.editorconfig +11 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +2 -0
- package/.yarn/versions/524dd037.yml +0 -0
- package/.yarn/versions/b57d536b.yml +0 -0
- package/.yarn/versions/d984e272.yml +0 -0
- package/cjs/defaults/index.d.ts +7 -0
- package/cjs/defaults/index.js +17 -0
- package/cjs/index.d.ts +5 -0
- package/cjs/index.js +24 -0
- package/{middleware → cjs/middleware}/axios.d.ts +2 -2
- package/cjs/middleware/axios.js +24 -0
- package/{middleware → cjs/middleware}/base.d.ts +3 -3
- package/cjs/middleware/base.js +52 -0
- package/{middleware → cjs/middleware}/express.d.ts +2 -2
- package/cjs/middleware/express.js +65 -0
- package/cjs/package.json +3 -0
- package/cjs/parsers/axios.d.ts +3 -0
- package/cjs/parsers/axios.js +55 -0
- package/cjs/parsers/jsonwebtoken.d.ts +3 -0
- package/{parsers → cjs/parsers}/jsonwebtoken.js +4 -4
- package/cjs/parsers/mikroorm.d.ts +3 -0
- package/{parsers → cjs/parsers}/mikroorm.js +7 -3
- package/cjs/parsers/tsoa.d.ts +3 -0
- package/{parsers → cjs/parsers}/tsoa.js +10 -4
- package/{problem.d.ts → cjs/problem.d.ts} +1 -1
- package/{problem.js → cjs/problem.js} +24 -23
- package/cjs/tsconfig.tsbuildinfo +1 -0
- package/{typings → cjs/typings}/codes.d.ts +1 -1
- package/{typings → cjs/typings}/events.d.ts +1 -1
- package/cjs/typings/index.d.ts +5 -0
- package/{typings → cjs/typings}/index.js +5 -5
- package/{typings → cjs/typings}/middleware.d.ts +1 -1
- package/{typings → cjs/typings}/parser.d.ts +1 -1
- package/{util → cjs/util}/events.d.ts +2 -2
- package/cjs/util/events.js +27 -0
- package/{util → cjs/util}/getProblems.d.ts +2 -2
- package/{util → cjs/util}/getProblems.js +10 -11
- package/{util → cjs/util}/isProblemArray.d.ts +1 -1
- package/{util → cjs/util}/isProblemArray.js +3 -4
- package/{util → cjs/util}/misc.d.ts +1 -1
- package/cjs/util/misc.js +19 -0
- package/{util → cjs/util}/version.d.ts +1 -1
- package/{util → cjs/util}/version.js +3 -3
- package/eslint.config.mjs +5 -0
- package/esm/defaults/4xx.d.ts +147 -0
- package/esm/defaults/4xx.js +148 -0
- package/esm/defaults/5xx.d.ts +57 -0
- package/esm/defaults/5xx.js +58 -0
- package/esm/defaults/aws.d.ts +12 -0
- package/esm/defaults/aws.js +13 -0
- package/esm/defaults/cloudflare.d.ts +47 -0
- package/esm/defaults/cloudflare.js +49 -0
- package/esm/defaults/iis.d.ts +17 -0
- package/esm/defaults/iis.js +18 -0
- package/esm/defaults/index.d.ts +7 -0
- package/esm/defaults/index.js +7 -0
- package/esm/defaults/nginx.d.ts +32 -0
- package/esm/defaults/nginx.js +33 -0
- package/esm/defaults/others.d.ts +37 -0
- package/esm/defaults/others.js +37 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +5 -0
- package/esm/middleware/axios.d.ts +13 -0
- package/esm/middleware/axios.js +20 -0
- package/esm/middleware/base.d.ts +24 -0
- package/esm/middleware/base.js +48 -0
- package/esm/middleware/express.d.ts +19 -0
- package/esm/middleware/express.js +61 -0
- package/esm/package.json +3 -0
- package/esm/parsers/axios.d.ts +3 -0
- package/esm/parsers/axios.js +53 -0
- package/esm/parsers/jsonwebtoken.d.ts +3 -0
- package/esm/parsers/jsonwebtoken.js +94 -0
- package/esm/parsers/mikroorm.d.ts +3 -0
- package/esm/parsers/mikroorm.js +17 -0
- package/esm/parsers/tsoa.d.ts +3 -0
- package/esm/parsers/tsoa.js +21 -0
- package/esm/problem.d.ts +14 -0
- package/esm/problem.js +56 -0
- package/esm/tsconfig.tsbuildinfo +1 -0
- package/esm/typings/codes.d.ts +5 -0
- package/esm/typings/codes.js +1 -0
- package/esm/typings/events.d.ts +2 -0
- package/esm/typings/events.js +1 -0
- package/esm/typings/index.d.ts +5 -0
- package/esm/typings/index.js +5 -0
- package/esm/typings/middleware.d.ts +9 -0
- package/esm/typings/middleware.js +1 -0
- package/esm/typings/parser.d.ts +2 -0
- package/esm/typings/parser.js +1 -0
- package/esm/typings/problem.d.ts +24 -0
- package/esm/typings/problem.js +11 -0
- package/esm/util/defaults.d.ts +4 -0
- package/esm/util/defaults.js +4 -0
- package/esm/util/events.d.ts +16 -0
- package/esm/util/events.js +25 -0
- package/esm/util/getProblems.d.ts +5 -0
- package/esm/util/getProblems.js +40 -0
- package/esm/util/isProblemArray.d.ts +2 -0
- package/esm/util/isProblemArray.js +6 -0
- package/esm/util/misc.d.ts +2 -0
- package/esm/util/misc.js +16 -0
- package/esm/util/version.d.ts +3 -0
- package/esm/util/version.js +16 -0
- package/package.json +51 -28
- package/scripts/ensureCorrectVersion.js +8 -4
- package/src/defaults/4xx.ts +149 -0
- package/src/defaults/5xx.ts +59 -0
- package/src/defaults/aws.ts +14 -0
- package/src/defaults/cloudflare.ts +50 -0
- package/src/defaults/iis.ts +19 -0
- package/src/defaults/index.ts +7 -0
- package/src/defaults/nginx.ts +34 -0
- package/src/defaults/others.ts +37 -0
- package/src/index.ts +5 -0
- package/src/middleware/axios.ts +29 -0
- package/src/middleware/base.ts +64 -0
- package/src/middleware/express.ts +72 -0
- package/src/parsers/axios.ts +61 -0
- package/src/parsers/jsonwebtoken.ts +104 -0
- package/src/parsers/mikroorm.ts +21 -0
- package/src/parsers/tsoa.ts +25 -0
- package/src/problem.ts +56 -0
- package/src/typings/codes.ts +6 -0
- package/src/typings/events.ts +3 -0
- package/src/typings/index.ts +5 -0
- package/src/typings/middleware.ts +11 -0
- package/src/typings/parser.ts +3 -0
- package/src/typings/problem.ts +27 -0
- package/src/util/defaults.ts +4 -0
- package/src/util/events.ts +34 -0
- package/src/util/getProblems.ts +43 -0
- package/src/util/isProblemArray.ts +6 -0
- package/src/util/misc.ts +20 -0
- package/src/util/version.ts +16 -0
- package/tsconfig.json +15 -0
- package/defaults/index.d.ts +0 -7
- package/defaults/index.js +0 -17
- package/index.d.ts +0 -5
- package/index.js +0 -39
- package/middleware/axios.js +0 -36
- package/middleware/base.js +0 -56
- package/middleware/express.js +0 -60
- package/parsers/axios.d.ts +0 -3
- package/parsers/axios.js +0 -41
- package/parsers/jsonwebtoken.d.ts +0 -3
- package/parsers/mikroorm.d.ts +0 -3
- package/parsers/tsoa.d.ts +0 -3
- package/tsconfig.tsbuildinfo +0 -1
- package/typings/index.d.ts +0 -5
- package/util/events.js +0 -29
- package/util/misc.js +0 -43
- /package/{defaults → cjs/defaults}/4xx.d.ts +0 -0
- /package/{defaults → cjs/defaults}/4xx.js +0 -0
- /package/{defaults → cjs/defaults}/5xx.d.ts +0 -0
- /package/{defaults → cjs/defaults}/5xx.js +0 -0
- /package/{defaults → cjs/defaults}/aws.d.ts +0 -0
- /package/{defaults → cjs/defaults}/aws.js +0 -0
- /package/{defaults → cjs/defaults}/cloudflare.d.ts +0 -0
- /package/{defaults → cjs/defaults}/cloudflare.js +0 -0
- /package/{defaults → cjs/defaults}/iis.d.ts +0 -0
- /package/{defaults → cjs/defaults}/iis.js +0 -0
- /package/{defaults → cjs/defaults}/nginx.d.ts +0 -0
- /package/{defaults → cjs/defaults}/nginx.js +0 -0
- /package/{defaults → cjs/defaults}/others.d.ts +0 -0
- /package/{defaults → cjs/defaults}/others.js +0 -0
- /package/{typings → cjs/typings}/codes.js +0 -0
- /package/{typings → cjs/typings}/events.js +0 -0
- /package/{typings → cjs/typings}/middleware.js +0 -0
- /package/{typings → cjs/typings}/parser.js +0 -0
- /package/{typings → cjs/typings}/problem.d.ts +0 -0
- /package/{typings → cjs/typings}/problem.js +0 -0
- /package/{util → cjs/util}/defaults.d.ts +0 -0
- /package/{util → cjs/util}/defaults.js +0 -0
package/.editorconfig
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { statusCodes as codes4xx } from '../defaults/4xx.js';
|
|
2
|
+
export { statusCodes as codes5xx } from '../defaults/5xx.js';
|
|
3
|
+
export { statusCodes as codesAws } from '../defaults/aws.js';
|
|
4
|
+
export { statusCodes as codesCloudflare } from '../defaults/cloudflare.js';
|
|
5
|
+
export { statusCodes as codesIis } from '../defaults/iis.js';
|
|
6
|
+
export { statusCodes as codesNginx } from '../defaults/nginx.js';
|
|
7
|
+
export { otherErrors } from '../defaults/others.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.otherErrors = exports.codesNginx = exports.codesIis = exports.codesCloudflare = exports.codesAws = exports.codes5xx = exports.codes4xx = void 0;
|
|
4
|
+
var _4xx_js_1 = require("../defaults/4xx.js");
|
|
5
|
+
Object.defineProperty(exports, "codes4xx", { enumerable: true, get: function () { return _4xx_js_1.statusCodes; } });
|
|
6
|
+
var _5xx_js_1 = require("../defaults/5xx.js");
|
|
7
|
+
Object.defineProperty(exports, "codes5xx", { enumerable: true, get: function () { return _5xx_js_1.statusCodes; } });
|
|
8
|
+
var aws_js_1 = require("../defaults/aws.js");
|
|
9
|
+
Object.defineProperty(exports, "codesAws", { enumerable: true, get: function () { return aws_js_1.statusCodes; } });
|
|
10
|
+
var cloudflare_js_1 = require("../defaults/cloudflare.js");
|
|
11
|
+
Object.defineProperty(exports, "codesCloudflare", { enumerable: true, get: function () { return cloudflare_js_1.statusCodes; } });
|
|
12
|
+
var iis_js_1 = require("../defaults/iis.js");
|
|
13
|
+
Object.defineProperty(exports, "codesIis", { enumerable: true, get: function () { return iis_js_1.statusCodes; } });
|
|
14
|
+
var nginx_js_1 = require("../defaults/nginx.js");
|
|
15
|
+
Object.defineProperty(exports, "codesNginx", { enumerable: true, get: function () { return nginx_js_1.statusCodes; } });
|
|
16
|
+
var others_js_1 = require("../defaults/others.js");
|
|
17
|
+
Object.defineProperty(exports, "otherErrors", { enumerable: true, get: function () { return others_js_1.otherErrors; } });
|
package/cjs/index.d.ts
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.events = exports.defaults = exports.Problem = void 0;
|
|
18
|
+
var problem_js_1 = require("./problem.js");
|
|
19
|
+
Object.defineProperty(exports, "Problem", { enumerable: true, get: function () { return problem_js_1.Problem; } });
|
|
20
|
+
exports.defaults = require("./defaults/index.js");
|
|
21
|
+
var events_js_1 = require("./util/events.js");
|
|
22
|
+
Object.defineProperty(exports, "events", { enumerable: true, get: function () { return events_js_1.default; } });
|
|
23
|
+
__exportStar(require("./typings/index.js"), exports);
|
|
24
|
+
__exportStar(require("./util/isProblemArray.js"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PartialMiddlewareOptions } from '../typings/middleware';
|
|
2
|
-
import { MiddlewareBase } from './base';
|
|
1
|
+
import type { PartialMiddlewareOptions } from '../typings/middleware.js';
|
|
2
|
+
import { MiddlewareBase } from './base.js';
|
|
3
3
|
type InterceptorArray = [undefined, (error: unknown) => Promise<never>];
|
|
4
4
|
export declare class AxiosMiddleware extends MiddlewareBase {
|
|
5
5
|
name: string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AxiosMiddleware = void 0;
|
|
4
|
+
const base_js_1 = require("./base.js");
|
|
5
|
+
const axios_js_1 = require("../parsers/axios.js");
|
|
6
|
+
const events_js_1 = require("../util/events.js");
|
|
7
|
+
class AxiosMiddleware extends base_js_1.MiddlewareBase {
|
|
8
|
+
name = 'axios';
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super({
|
|
11
|
+
'parsers': [axios_js_1.default]
|
|
12
|
+
}, options);
|
|
13
|
+
}
|
|
14
|
+
interceptor = async (error) => {
|
|
15
|
+
const problems = await this.parse(error);
|
|
16
|
+
events_js_1.default.emit(problems);
|
|
17
|
+
return Promise.reject(problems);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @example instance.interceptors.response.use(...middleware.use())
|
|
21
|
+
*/
|
|
22
|
+
use = () => [undefined, this.interceptor];
|
|
23
|
+
}
|
|
24
|
+
exports.AxiosMiddleware = AxiosMiddleware;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Problem } from '../problem';
|
|
2
|
-
import type { ProblemOpts } from '../typings';
|
|
3
|
-
import type { MiddlewareOptions, PartialMiddlewareOptions } from '../typings/middleware';
|
|
1
|
+
import { Problem } from '../problem.js';
|
|
2
|
+
import type { ProblemOpts } from '../typings/index.js';
|
|
3
|
+
import type { MiddlewareOptions, PartialMiddlewareOptions } from '../typings/middleware.js';
|
|
4
4
|
/**
|
|
5
5
|
* Middleware collects errors from somewhere, transforms them into something recognizable by a parser, and then passes them to the parsers, and then returns an array of Problems to whatever is using the middleware
|
|
6
6
|
*/
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MiddlewareBase = void 0;
|
|
4
|
+
const index_js_1 = require("../defaults/index.js");
|
|
5
|
+
const problem_js_1 = require("../problem.js");
|
|
6
|
+
const getProblems_js_1 = require("../util/getProblems.js");
|
|
7
|
+
/**
|
|
8
|
+
* Middleware collects errors from somewhere, transforms them into something recognizable by a parser, and then passes them to the parsers, and then returns an array of Problems to whatever is using the middleware
|
|
9
|
+
*/
|
|
10
|
+
class MiddlewareBase {
|
|
11
|
+
options;
|
|
12
|
+
/**
|
|
13
|
+
* When nothing is returned from the parsers, just throw in a default "fallback" Problem object, so that a Problem is still actually returned/emitted
|
|
14
|
+
*/
|
|
15
|
+
enableFallback = true;
|
|
16
|
+
constructor(defaultOptions, options) {
|
|
17
|
+
this.options = { ...defaultOptions, ...options };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse input using parsers
|
|
21
|
+
*/
|
|
22
|
+
parse = async (input) => {
|
|
23
|
+
const problems = [];
|
|
24
|
+
const prob = (0, getProblems_js_1.getProblems)(input);
|
|
25
|
+
if (!prob) {
|
|
26
|
+
for (const parse of this.options.parsers) {
|
|
27
|
+
const resp = parse(input);
|
|
28
|
+
if (!resp.length)
|
|
29
|
+
continue;
|
|
30
|
+
problems.push(...resp);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (!problems.length && this.enableFallback) {
|
|
34
|
+
problems.push(new problem_js_1.Problem({
|
|
35
|
+
...this.fallback,
|
|
36
|
+
'errorObject': input,
|
|
37
|
+
'stack': (typeof input === 'object' && input !== null && 'stack' in input && typeof input.stack === 'string') ? input.stack : undefined
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
problems.push(...prob);
|
|
43
|
+
}
|
|
44
|
+
for (const p of problems) {
|
|
45
|
+
if (!p.middleware)
|
|
46
|
+
p.middleware = this.name;
|
|
47
|
+
}
|
|
48
|
+
return problems;
|
|
49
|
+
};
|
|
50
|
+
fallback = index_js_1.otherErrors.unknown;
|
|
51
|
+
}
|
|
52
|
+
exports.MiddlewareBase = MiddlewareBase;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import type { PartialMiddlewareOptions } from '../typings/middleware';
|
|
3
|
-
import { MiddlewareBase } from './base';
|
|
2
|
+
import type { PartialMiddlewareOptions } from '../typings/middleware.js';
|
|
3
|
+
import { MiddlewareBase } from './base.js';
|
|
4
4
|
export declare class ExpressMiddleware extends MiddlewareBase {
|
|
5
5
|
name: string;
|
|
6
6
|
middleware: (error: unknown, req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpressMiddleware = void 0;
|
|
4
|
+
const base_js_1 = require("./base.js");
|
|
5
|
+
const problem_js_1 = require("../problem.js");
|
|
6
|
+
const index_js_1 = require("../defaults/index.js");
|
|
7
|
+
const events_js_1 = require("../util/events.js");
|
|
8
|
+
const defaults_js_1 = require("../util/defaults.js");
|
|
9
|
+
class ExpressMiddleware extends base_js_1.MiddlewareBase {
|
|
10
|
+
name = 'express';
|
|
11
|
+
middleware = (error, req, res, next) => {
|
|
12
|
+
this.parse(error)
|
|
13
|
+
.then(problems => {
|
|
14
|
+
for (const problem of problems) {
|
|
15
|
+
if (problem.instance === defaults_js_1.defaultInstance) {
|
|
16
|
+
problem.instance = req.originalUrl;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
events_js_1.default.emit(problems);
|
|
20
|
+
res
|
|
21
|
+
.contentType('application/problem+json')
|
|
22
|
+
.status(problems[0]?.status ?? 500)
|
|
23
|
+
.json(problems.map(val => val.toObject()));
|
|
24
|
+
})
|
|
25
|
+
.catch(err => {
|
|
26
|
+
res
|
|
27
|
+
.contentType('application/problem+json')
|
|
28
|
+
.status(500)
|
|
29
|
+
.json([
|
|
30
|
+
new problem_js_1.Problem({
|
|
31
|
+
...index_js_1.otherErrors.unknown,
|
|
32
|
+
'instance': req.originalUrl,
|
|
33
|
+
'status': 500,
|
|
34
|
+
'stack': err?.stack,
|
|
35
|
+
'errorObject': err,
|
|
36
|
+
}).toObject()
|
|
37
|
+
]);
|
|
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
|
+
use = () => this.middleware;
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super({
|
|
49
|
+
'parsers': []
|
|
50
|
+
}, options);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Put this right before the middleware.use() to catch all 404 errors and respond with a Problem instead of the default Express response
|
|
54
|
+
* @example app.use(middleware.notFound)
|
|
55
|
+
*/
|
|
56
|
+
notFound = (req, res, next) => {
|
|
57
|
+
const error = new problem_js_1.Problem({
|
|
58
|
+
...index_js_1.codes4xx[404],
|
|
59
|
+
'instance': req.originalUrl,
|
|
60
|
+
'detail': `No API endpoints exist on ${req.url} for request method ${req.method}`
|
|
61
|
+
});
|
|
62
|
+
return next(error);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.ExpressMiddleware = ExpressMiddleware;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const others_js_1 = require("../defaults/others.js");
|
|
4
|
+
const problem_js_1 = require("../problem.js");
|
|
5
|
+
const getProblems_js_1 = require("../util/getProblems.js");
|
|
6
|
+
const misc_js_1 = require("../util/misc.js");
|
|
7
|
+
function isAxiosError(payload) {
|
|
8
|
+
return typeof payload === 'object' && payload !== null && 'isAxiosError' in payload && payload.isAxiosError === true;
|
|
9
|
+
}
|
|
10
|
+
const parse = (input) => {
|
|
11
|
+
if (typeof input !== 'object' || input == null)
|
|
12
|
+
return [];
|
|
13
|
+
if (!isAxiosError(input))
|
|
14
|
+
return [];
|
|
15
|
+
const request = input.request;
|
|
16
|
+
if (input?.response?.data) {
|
|
17
|
+
const problems = (0, getProblems_js_1.getProblems)(input?.response?.data);
|
|
18
|
+
if (problems?.length)
|
|
19
|
+
return problems;
|
|
20
|
+
}
|
|
21
|
+
if (input?.response) {
|
|
22
|
+
const opts = (0, misc_js_1.getHttpError)(input.response.status);
|
|
23
|
+
if (opts)
|
|
24
|
+
return [new problem_js_1.Problem({
|
|
25
|
+
...opts,
|
|
26
|
+
'instance': input?.config?.url,
|
|
27
|
+
'stack': input?.stack,
|
|
28
|
+
'errorObject': input
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
// TODO: Fix this, this seems bad
|
|
32
|
+
if (request) {
|
|
33
|
+
const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
|
|
34
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
35
|
+
if (isBrowser && request instanceof XMLHttpRequest) {
|
|
36
|
+
return [new problem_js_1.Problem({
|
|
37
|
+
...others_js_1.otherErrors.networkError,
|
|
38
|
+
'instance': input?.config?.url,
|
|
39
|
+
'stack': input?.stack,
|
|
40
|
+
'errorObject': input
|
|
41
|
+
})];
|
|
42
|
+
}
|
|
43
|
+
// Probably a ClientRequest
|
|
44
|
+
if (isNode && 'pipe' in request && 'destroy' in request) {
|
|
45
|
+
return [new problem_js_1.Problem({
|
|
46
|
+
...others_js_1.otherErrors.networkError,
|
|
47
|
+
'instance': input?.config?.url,
|
|
48
|
+
'stack': input?.stack,
|
|
49
|
+
'errorObject': input
|
|
50
|
+
})];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
};
|
|
55
|
+
exports.default = parse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const problem_js_1 = require("../problem.js");
|
|
4
4
|
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
5
5
|
const errorMap = [
|
|
6
6
|
{
|
|
@@ -72,11 +72,11 @@ const parse = (input) => {
|
|
|
72
72
|
if (input instanceof jsonwebtoken_1.JsonWebTokenError && input.name === 'JsonWebTokenError') {
|
|
73
73
|
const found = errorMap.find(val => typeof val.search === 'string' ? val.search === input.message : val.search.test(input.message));
|
|
74
74
|
if (found) {
|
|
75
|
-
return [new
|
|
75
|
+
return [new problem_js_1.Problem(found.result)];
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
else if (input instanceof jsonwebtoken_1.TokenExpiredError && input.name === 'TokenExpiredError') {
|
|
79
|
-
return [new
|
|
79
|
+
return [new problem_js_1.Problem({
|
|
80
80
|
'title': 'The JSON Web Token has expired',
|
|
81
81
|
'type': '/errors/jsonwebtoken/tokenexpired',
|
|
82
82
|
'detail': `The JSON Web Token expired at ${input.expiredAt}`,
|
|
@@ -84,7 +84,7 @@ const parse = (input) => {
|
|
|
84
84
|
})];
|
|
85
85
|
}
|
|
86
86
|
else if (input instanceof jsonwebtoken_1.NotBeforeError && input.name === 'NotBeforeError') {
|
|
87
|
-
return [new
|
|
87
|
+
return [new problem_js_1.Problem({
|
|
88
88
|
'title': 'The JSON Web Token is not valid yet',
|
|
89
89
|
'type': '/errors/jsonwebtoken/notbefore',
|
|
90
90
|
'detail': `The JSON Web Token is not valid before ${input.date}`,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const problem_js_1 = require("../problem.js");
|
|
4
|
+
const _4xx_js_1 = require("../defaults/4xx.js");
|
|
5
5
|
const core_1 = require("@mikro-orm/core");
|
|
6
6
|
// TODO: Make this less bad
|
|
7
7
|
const parse = (input) => {
|
|
@@ -9,7 +9,11 @@ const parse = (input) => {
|
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
11
|
return [
|
|
12
|
-
new
|
|
12
|
+
new problem_js_1.Problem({
|
|
13
|
+
..._4xx_js_1.statusCodes['404'],
|
|
14
|
+
'stack': input.stack,
|
|
15
|
+
'errorObject': input,
|
|
16
|
+
})
|
|
13
17
|
];
|
|
14
18
|
};
|
|
15
19
|
exports.default = parse;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tsoa_1 = require("tsoa");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const problem_js_1 = require("../problem.js");
|
|
5
|
+
const others_js_1 = require("../defaults/others.js");
|
|
6
6
|
const parse = (input) => {
|
|
7
7
|
if (!(input instanceof tsoa_1.ValidateError)) {
|
|
8
8
|
return [];
|
|
9
9
|
}
|
|
10
10
|
// TODO: Give actual useful responses instead of this shit
|
|
11
11
|
return [
|
|
12
|
-
new
|
|
12
|
+
new problem_js_1.Problem({
|
|
13
|
+
...others_js_1.otherErrors.inputValidationError,
|
|
14
|
+
'detail': input.message,
|
|
15
|
+
'status': input.status,
|
|
16
|
+
'data': {
|
|
13
17
|
'fields': input.fields,
|
|
14
|
-
},
|
|
18
|
+
},
|
|
19
|
+
'stack': input.stack,
|
|
20
|
+
})
|
|
15
21
|
];
|
|
16
22
|
};
|
|
17
23
|
exports.default = parse;
|
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Problem = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const defaults_js_1 = require("./util/defaults.js");
|
|
5
|
+
const version_js_1 = require("./util/version.js");
|
|
6
6
|
class Problem extends Error {
|
|
7
|
+
type = defaults_js_1.defaultType;
|
|
8
|
+
title = defaults_js_1.defaultTitle;
|
|
9
|
+
status = 500;
|
|
10
|
+
detail = defaults_js_1.defaultDetail;
|
|
11
|
+
instance = defaults_js_1.defaultInstance;
|
|
12
|
+
errorObject;
|
|
13
|
+
__problemVersion = version_js_1.version;
|
|
14
|
+
data = undefined;
|
|
15
|
+
middleware;
|
|
7
16
|
constructor({ type, title, status, detail, instance, stack, errorObject, data, middleware }) {
|
|
8
|
-
|
|
9
|
-
super((_a = detail !== null && detail !== void 0 ? detail : title) !== null && _a !== void 0 ? _a : 'HTTP Problem Details');
|
|
10
|
-
this.type = defaults_1.defaultType;
|
|
11
|
-
this.title = defaults_1.defaultTitle;
|
|
12
|
-
this.status = 500;
|
|
13
|
-
this.detail = defaults_1.defaultDetail;
|
|
14
|
-
this.instance = defaults_1.defaultInstance;
|
|
15
|
-
this.__problemVersion = version_1.version;
|
|
16
|
-
this.data = undefined;
|
|
17
|
-
this.toObject = () => {
|
|
18
|
-
return {
|
|
19
|
-
'type': this.type,
|
|
20
|
-
'title': this.title,
|
|
21
|
-
'status': this.status,
|
|
22
|
-
'detail': this.detail,
|
|
23
|
-
'instance': this.instance,
|
|
24
|
-
'__problemVersion': this.__problemVersion,
|
|
25
|
-
'data': this.data
|
|
26
|
-
};
|
|
27
|
-
};
|
|
17
|
+
super(detail ?? title ?? 'HTTP Problem Details');
|
|
28
18
|
// TODO: Figure out why i wrote this?
|
|
29
19
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
30
20
|
this.type = type;
|
|
@@ -49,11 +39,22 @@ class Problem extends Error {
|
|
|
49
39
|
Error.captureStackTrace(this, this.constructor);
|
|
50
40
|
}
|
|
51
41
|
else {
|
|
52
|
-
this.stack = new Error(
|
|
42
|
+
this.stack = new Error(detail ?? title ?? 'HTTP Problem Details').stack;
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
45
|
if (data)
|
|
56
46
|
this.data = data;
|
|
57
47
|
}
|
|
48
|
+
toObject = () => {
|
|
49
|
+
return {
|
|
50
|
+
'type': this.type,
|
|
51
|
+
'title': this.title,
|
|
52
|
+
'status': this.status,
|
|
53
|
+
'detail': this.detail,
|
|
54
|
+
'instance': this.instance,
|
|
55
|
+
'__problemVersion': this.__problemVersion,
|
|
56
|
+
'data': this.data
|
|
57
|
+
};
|
|
58
|
+
};
|
|
58
59
|
}
|
|
59
60
|
exports.Problem = Problem;
|