@swell/cli 2.9.5 → 2.9.6
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.
|
@@ -93,6 +93,36 @@ export function createMockRequest(options: MockRequestOptions = {}): SwellReques
|
|
|
93
93
|
query,
|
|
94
94
|
initialize: async () => {},
|
|
95
95
|
parseJson: (input: string) => JSON.parse(input),
|
|
96
|
+
reject: (
|
|
97
|
+
code: string,
|
|
98
|
+
message: string,
|
|
99
|
+
options: { status?: number } = {}
|
|
100
|
+
) => {
|
|
101
|
+
const status =
|
|
102
|
+
typeof options.status === "number" &&
|
|
103
|
+
options.status >= 400 &&
|
|
104
|
+
options.status < 500
|
|
105
|
+
? options.status
|
|
106
|
+
: 422;
|
|
107
|
+
const error = new Error(
|
|
108
|
+
message || "Request rejected by function"
|
|
109
|
+
) as Error & {
|
|
110
|
+
body: { $reject: { code: string; message: string; status: number } };
|
|
111
|
+
code: string;
|
|
112
|
+
status: number;
|
|
113
|
+
};
|
|
114
|
+
error.name = "SwellRejection";
|
|
115
|
+
error.code = code;
|
|
116
|
+
error.status = status;
|
|
117
|
+
error.body = {
|
|
118
|
+
$reject: {
|
|
119
|
+
code,
|
|
120
|
+
message: error.message,
|
|
121
|
+
status,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
return error;
|
|
125
|
+
},
|
|
96
126
|
appValues: (idOrValues: string | SwellData, values?: SwellData) => {
|
|
97
127
|
const targetAppId =
|
|
98
128
|
typeof idOrValues === "string" ? idOrValues : resolvedAppId;
|
|
@@ -17,8 +17,43 @@ class SwellErrorImpl extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
class SwellRejectionImpl extends Error {
|
|
21
|
+
status: number;
|
|
22
|
+
code: string;
|
|
23
|
+
body: {
|
|
24
|
+
$reject: {
|
|
25
|
+
code: string;
|
|
26
|
+
message: string;
|
|
27
|
+
status: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
constructor(code: string, message: string, options: { status?: number } = {}) {
|
|
32
|
+
const status =
|
|
33
|
+
typeof options.status === "number" &&
|
|
34
|
+
options.status >= 400 &&
|
|
35
|
+
options.status < 500
|
|
36
|
+
? options.status
|
|
37
|
+
: 422;
|
|
38
|
+
|
|
39
|
+
super(message || "Request rejected by function");
|
|
40
|
+
this.name = "SwellRejection";
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.code = code;
|
|
43
|
+
this.body = {
|
|
44
|
+
$reject: {
|
|
45
|
+
code,
|
|
46
|
+
message: this.message,
|
|
47
|
+
status,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
20
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
54
|
(globalThis as any).SwellError = SwellErrorImpl;
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
(globalThis as any).SwellRejection = SwellRejectionImpl;
|
|
22
57
|
|
|
23
58
|
export {};
|
|
24
59
|
`;
|
|
@@ -230,6 +230,9 @@ class SwellRequest {
|
|
|
230
230
|
},
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
+
reject(code, message, options = {}) {
|
|
234
|
+
return new SwellRejection(code, message, options);
|
|
235
|
+
}
|
|
233
236
|
}
|
|
234
237
|
/**
|
|
235
238
|
* Class representing the Swell backend API.
|
|
@@ -414,6 +417,26 @@ class SwellError extends Error {
|
|
|
414
417
|
return RETRYABLE_CODES.has(this.code);
|
|
415
418
|
}
|
|
416
419
|
}
|
|
420
|
+
class SwellRejection extends Error {
|
|
421
|
+
constructor(code, message, options = {}) {
|
|
422
|
+
const status = typeof options.status === 'number' &&
|
|
423
|
+
options.status >= 400 &&
|
|
424
|
+
options.status < 500
|
|
425
|
+
? options.status
|
|
426
|
+
: 422;
|
|
427
|
+
super(message || 'Request rejected by function');
|
|
428
|
+
this.name = 'SwellRejection';
|
|
429
|
+
this.status = status;
|
|
430
|
+
this.code = code;
|
|
431
|
+
this.body = {
|
|
432
|
+
$reject: {
|
|
433
|
+
code,
|
|
434
|
+
message: this.message,
|
|
435
|
+
status,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
}
|
|
417
440
|
/**
|
|
418
441
|
* Class representing a Swell response.
|
|
419
442
|
*/
|
package/oclif.manifest.json
CHANGED