Skip to content

Commit 4cb876b

Browse files
Create throw-error.mjs (#13998)
* Create throw-error.mjs * fixing up to handle custom errors
1 parent de6204f commit 4cb876b

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import error from "../../error.app.mjs";
2+
3+
export default {
4+
name: "Throw Error",
5+
version: "0.0.1",
6+
key: "error-throw-error",
7+
description: "Quickly throw an error from your workflow.",
8+
props: {
9+
error,
10+
name: {
11+
propDefinition: [
12+
error,
13+
"name",
14+
],
15+
},
16+
errorMessage: {
17+
propDefinition: [
18+
error,
19+
"errorMessage",
20+
],
21+
},
22+
},
23+
type: "action",
24+
async run() {
25+
this.error.maybeCreateAndThrowError(this.name, this.errorMessage);
26+
},
27+
};

components/error/error.app.mjs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
export default {
22
type: "app",
33
app: "error",
4-
propDefinitions: {},
4+
propDefinitions: {
5+
name: {
6+
type: "string",
7+
label: "Error Name",
8+
description:
9+
"The **name** (class) of error to throw, which you can define as any custom string. This will show up in all of the standard Pipedream error handling destinations.",
10+
default: "Error",
11+
},
12+
errorMessage: {
13+
type: "string",
14+
label: "Error Message",
15+
description:
16+
"The error **message** to throw. This will show up in all of the standard Pipedream error handling destinations.",
17+
optional: true,
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
maybeCreateAndThrowError(name, message) {
22+
const errorClass = global[name];
23+
24+
// Check if the error class exists and is a subclass of Error
25+
if (
26+
typeof errorClass === "function" &&
27+
errorClass.prototype.isPrototypeOf.call(Error)
28+
) {
29+
throw new errorClass(message);
30+
}
31+
32+
class DynamicError extends Error {
33+
constructor(msg) {
34+
super(msg);
35+
this.name = name;
36+
}
37+
}
38+
throw new DynamicError(message);
939
},
1040
},
11-
};
41+
};

components/error/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/error",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Pipedream Error Components",
55
"main": "error.app.mjs",
66
"keywords": [
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)