Skip to content

Commit

Permalink
Create throw-error.mjs (#13998)
Browse files Browse the repository at this point in the history
* Create throw-error.mjs

* fixing up to handle custom errors
  • Loading branch information
dannyroosevelt authored Sep 18, 2024
1 parent de6204f commit 4cb876b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
27 changes: 27 additions & 0 deletions components/error/actions/throw-error/throw-error.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import error from "../../error.app.mjs";

export default {
name: "Throw Error",
version: "0.0.1",
key: "error-throw-error",
description: "Quickly throw an error from your workflow.",
props: {
error,
name: {
propDefinition: [
error,
"name",
],
},
errorMessage: {
propDefinition: [
error,
"errorMessage",
],
},
},
type: "action",
async run() {
this.error.maybeCreateAndThrowError(this.name, this.errorMessage);
},
};
40 changes: 35 additions & 5 deletions components/error/error.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
export default {
type: "app",
app: "error",
propDefinitions: {},
propDefinitions: {
name: {
type: "string",
label: "Error Name",
description:
"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.",
default: "Error",
},
errorMessage: {
type: "string",
label: "Error Message",
description:
"The error **message** to throw. This will show up in all of the standard Pipedream error handling destinations.",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
maybeCreateAndThrowError(name, message) {
const errorClass = global[name];

// Check if the error class exists and is a subclass of Error
if (
typeof errorClass === "function" &&
errorClass.prototype.isPrototypeOf.call(Error)
) {
throw new errorClass(message);
}

class DynamicError extends Error {
constructor(msg) {
super(msg);
this.name = name;
}
}
throw new DynamicError(message);
},
},
};
};
4 changes: 2 additions & 2 deletions components/error/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/error",
"version": "0.0.1",
"version": "0.0.2",
"description": "Pipedream Error Components",
"main": "error.app.mjs",
"keywords": [
Expand All @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}

0 comments on commit 4cb876b

Please sign in to comment.