-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create throw-error.mjs * fixing up to handle custom errors
- Loading branch information
1 parent
de6204f
commit 4cb876b
Showing
3 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters