diff --git a/components/error/actions/throw-error/throw-error.mjs b/components/error/actions/throw-error/throw-error.mjs new file mode 100644 index 0000000000000..4a724026334cb --- /dev/null +++ b/components/error/actions/throw-error/throw-error.mjs @@ -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); + }, +}; diff --git a/components/error/error.app.mjs b/components/error/error.app.mjs index d8fa9888c1133..c7ced7cce41ab 100644 --- a/components/error/error.app.mjs +++ b/components/error/error.app.mjs @@ -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); }, }, -}; \ No newline at end of file +}; diff --git a/components/error/package.json b/components/error/package.json index eee25f9d8fe44..91f83c7bed9f5 100644 --- a/components/error/package.json +++ b/components/error/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/error", - "version": "0.0.1", + "version": "0.0.2", "description": "Pipedream Error Components", "main": "error.app.mjs", "keywords": [ @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +}