1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | const errorParser = ({
|
7 | err
|
8 | }) => {
|
9 | const handlers = [{
|
10 | regex: /(.+) is not defined/m,
|
11 | cb: match => {
|
12 | return {
|
13 | id: `11330`,
|
14 | context: {
|
15 | message: match[0],
|
16 | arg: match[1]
|
17 | }
|
18 | };
|
19 | }
|
20 | },
|
21 | {
|
22 | regex: /[\s\S]*/gm,
|
23 | cb: match => {
|
24 | return {
|
25 | id: `11321`,
|
26 | context: {
|
27 | message: err instanceof Error ? match[0] : err
|
28 | },
|
29 | error: err instanceof Error ? err : undefined
|
30 | };
|
31 | }
|
32 | }];
|
33 | let structured;
|
34 |
|
35 | for (const {
|
36 | regex,
|
37 | cb
|
38 | } of handlers) {
|
39 | var _err;
|
40 |
|
41 | if (Array.isArray(err)) {
|
42 | err = err[0];
|
43 | }
|
44 |
|
45 | if (err.message) {
|
46 | err = err.message;
|
47 | }
|
48 |
|
49 | const matched = (_err = err) === null || _err === void 0 ? void 0 : _err.match(regex);
|
50 |
|
51 | if (matched) {
|
52 | structured = Object.assign({}, cb(matched));
|
53 | break;
|
54 | }
|
55 | }
|
56 |
|
57 | return structured;
|
58 | };
|
59 |
|
60 | var _default = errorParser;
|
61 | exports.default = _default;
|
62 |
|
\ | No newline at end of file |