skapi-js 0.0.1

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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Skapi throws custom error.
3
+ * You can check error instance by:
4
+ * if(err instanceof SkapiError) {
5
+ * // Skapi had an error
6
+ * }
7
+ */
8
+ export default class SkapiError extends Error {
9
+ code: string | number;
10
+ cause: Error;
11
+ constructor(
12
+ error: any,
13
+ options?: {
14
+ code?: string;
15
+ cause?: Error;
16
+ }) {
17
+
18
+ if (error instanceof Error) {
19
+ super(error.message || 'Something went wrong.');
20
+ this.cause = error;
21
+ this.name = error.name;
22
+ if (error.hasOwnProperty('code')) {
23
+ this.code = (error as any).code;
24
+ }
25
+ }
26
+
27
+ else if (typeof error === 'string') {
28
+ super(error || 'Something went wrong.');
29
+ this.name = "SkapiError";
30
+ this.code = 'ERROR';
31
+
32
+ if (options) {
33
+ if (options.code) {
34
+ this.code = options.code;
35
+ }
36
+
37
+ if (options.cause) {
38
+ this.cause = options.cause;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }