@ooneex/exception 0.0.12 → 0.0.13
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/dist/index.js +137 -3
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/BadRequestException.ts
|
|
2
|
+
import { HttpStatus } from "@ooneex/http-status";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/Exception.ts
|
|
5
|
+
class Exception extends Error {
|
|
6
|
+
date = new Date;
|
|
7
|
+
status;
|
|
8
|
+
data;
|
|
9
|
+
native;
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message instanceof Error ? message.message : message);
|
|
12
|
+
this.status = options?.status || 500;
|
|
13
|
+
this.data = options?.data || {};
|
|
14
|
+
if (message instanceof Error) {
|
|
15
|
+
this.native = message;
|
|
16
|
+
}
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
this.data = Object.freeze(this.data);
|
|
19
|
+
}
|
|
20
|
+
stackToJson() {
|
|
21
|
+
if (!this.stack) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const stackLines = this.stack.split(`
|
|
25
|
+
`);
|
|
26
|
+
const frames = [];
|
|
27
|
+
for (let i = 1;i < stackLines.length; i++) {
|
|
28
|
+
const line = stackLines[i]?.trim();
|
|
29
|
+
if (!line)
|
|
30
|
+
continue;
|
|
31
|
+
const frame = {
|
|
32
|
+
source: line
|
|
33
|
+
};
|
|
34
|
+
const atMatch = line.match(/^\s*at\s+(.+)$/);
|
|
35
|
+
if (atMatch) {
|
|
36
|
+
const content = atMatch[1];
|
|
37
|
+
const funcWithLocationMatch = content?.match(/^(.+?)\s+\((.+)\)$/);
|
|
38
|
+
if (funcWithLocationMatch) {
|
|
39
|
+
const functionName = funcWithLocationMatch[1];
|
|
40
|
+
const location = funcWithLocationMatch[2];
|
|
41
|
+
if (functionName) {
|
|
42
|
+
frame.functionName = functionName;
|
|
43
|
+
}
|
|
44
|
+
const locationMatch = location?.match(/^(.+):(\d+):(\d+)$/);
|
|
45
|
+
if (locationMatch) {
|
|
46
|
+
const fileName = locationMatch[1];
|
|
47
|
+
const lineNum = locationMatch[2];
|
|
48
|
+
const colNum = locationMatch[3];
|
|
49
|
+
if (fileName) {
|
|
50
|
+
frame.fileName = fileName;
|
|
51
|
+
}
|
|
52
|
+
if (lineNum) {
|
|
53
|
+
frame.lineNumber = Number.parseInt(lineNum, 10);
|
|
54
|
+
}
|
|
55
|
+
if (colNum) {
|
|
56
|
+
frame.columnNumber = Number.parseInt(colNum, 10);
|
|
57
|
+
}
|
|
58
|
+
} else if (location) {
|
|
59
|
+
frame.fileName = location;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
const directLocationMatch = content?.match(/^(.+):(\d+):(\d+)$/);
|
|
63
|
+
if (directLocationMatch) {
|
|
64
|
+
const fileName = directLocationMatch[1];
|
|
65
|
+
const lineNum = directLocationMatch[2];
|
|
66
|
+
const colNum = directLocationMatch[3];
|
|
67
|
+
if (fileName) {
|
|
68
|
+
frame.fileName = fileName;
|
|
69
|
+
}
|
|
70
|
+
if (lineNum) {
|
|
71
|
+
frame.lineNumber = Number.parseInt(lineNum, 10);
|
|
72
|
+
}
|
|
73
|
+
if (colNum) {
|
|
74
|
+
frame.columnNumber = Number.parseInt(colNum, 10);
|
|
75
|
+
}
|
|
76
|
+
} else if (content) {
|
|
77
|
+
frame.functionName = content;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
frames.push(frame);
|
|
82
|
+
}
|
|
83
|
+
return frames;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/BadRequestException.ts
|
|
88
|
+
class BadRequestException extends Exception {
|
|
89
|
+
constructor(message, data = {}) {
|
|
90
|
+
super(message, {
|
|
91
|
+
status: HttpStatus.Code.BadRequest,
|
|
92
|
+
data
|
|
93
|
+
});
|
|
94
|
+
this.name = "BadRequestException";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// src/MethodNotAllowedException.ts
|
|
98
|
+
import { HttpStatus as HttpStatus2 } from "@ooneex/http-status";
|
|
99
|
+
class MethodNotAllowedException extends Exception {
|
|
100
|
+
constructor(message, data = {}) {
|
|
101
|
+
super(message, {
|
|
102
|
+
status: HttpStatus2.Code.MethodNotAllowed,
|
|
103
|
+
data
|
|
104
|
+
});
|
|
105
|
+
this.name = "MethodNotAllowedException";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// src/NotFoundException.ts
|
|
109
|
+
import { HttpStatus as HttpStatus3 } from "@ooneex/http-status";
|
|
110
|
+
class NotFoundException extends Exception {
|
|
111
|
+
constructor(message, data = {}) {
|
|
112
|
+
super(message, {
|
|
113
|
+
status: HttpStatus3.Code.NotFound,
|
|
114
|
+
data
|
|
115
|
+
});
|
|
116
|
+
this.name = "NotFoundException";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// src/UnauthorizedException.ts
|
|
120
|
+
import { HttpStatus as HttpStatus4 } from "@ooneex/http-status";
|
|
121
|
+
class UnauthorizedException extends Exception {
|
|
122
|
+
constructor(message, data = {}) {
|
|
123
|
+
super(message, {
|
|
124
|
+
status: HttpStatus4.Code.Unauthorized,
|
|
125
|
+
data
|
|
126
|
+
});
|
|
127
|
+
this.name = "UnauthorizedException";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
UnauthorizedException,
|
|
132
|
+
NotFoundException,
|
|
133
|
+
MethodNotAllowedException,
|
|
134
|
+
Exception,
|
|
135
|
+
BadRequestException
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//# debugId=61ED8CC9C66369BB64756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"import { HttpStatus } from \"@ooneex/http-status\";\nimport { Exception } from \"./Exception\";\n\nexport class NotFoundException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.NotFound,\n data,\n });\n this.name = \"NotFoundException\";\n }\n}\n",
|
|
9
9
|
"import { HttpStatus } from \"@ooneex/http-status\";\nimport { Exception } from \"./Exception\";\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.Unauthorized,\n data,\n });\n this.name = \"UnauthorizedException\";\n }\n}\n"
|
|
10
10
|
],
|
|
11
|
-
"mappings": "AAAA,
|
|
12
|
-
"debugId": "
|
|
11
|
+
"mappings": ";AAAA;;;ACGO,MAAM,kBAAkB,MAA4B;AAAA,EACzC,OAAa,IAAI;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,WAAW,CAAC,SAAyB,SAAuE;AAAA,IAC1G,MAAM,mBAAmB,QAAS,QAAkB,UAAU,OAAO;AAAA,IAErE,KAAK,SAAS,SAAS,UAAU;AAAA,IACjC,KAAK,OAAO,SAAS,QAAQ,CAAC;AAAA,IAE9B,IAAI,mBAAmB,OAAO;AAAA,MAC5B,KAAK,SAAS;AAAA,IAChB;AAAA,IACA,KAAK,OAAO,KAAK,YAAY;AAAA,IAC7B,KAAK,OAAO,OAAO,OAAO,KAAK,IAAI;AAAA;AAAA,EAO9B,WAAW,GAAqC;AAAA,IACrD,IAAI,CAAC,KAAK,OAAO;AAAA,MACf,OAAO;AAAA,IACT;AAAA,IAEA,MAAM,aAAa,KAAK,MAAM,MAAM;AAAA,CAAI;AAAA,IACxC,MAAM,SAAoC,CAAC;AAAA,IAG3C,SAAS,IAAI,EAAG,IAAI,WAAW,QAAQ,KAAK;AAAA,MAC1C,MAAM,OAAO,WAAW,IAAI,KAAK;AAAA,MACjC,IAAI,CAAC;AAAA,QAAM;AAAA,MAEX,MAAM,QAAiC;AAAA,QACrC,QAAQ;AAAA,MACV;AAAA,MAOA,MAAM,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