|
@@ -1,37 +1,25 @@
|
|
import { getBlockConnection } from '../helper';
|
|
import { getBlockConnection } from '../helper';
|
|
|
|
+import { isWhitespace } from '@/utils/helper';
|
|
import { executeWebhook } from '@/utils/webhookUtil';
|
|
import { executeWebhook } from '@/utils/webhookUtil';
|
|
|
|
|
|
-function webhook({ data, outputs }) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- const nextBlockId = getBlockConnection({ outputs });
|
|
|
|
|
|
+export async function webhook({ data, outputs }) {
|
|
|
|
+ const nextBlockId = getBlockConnection({ outputs });
|
|
|
|
|
|
- if (!data.url) {
|
|
|
|
- const error = new Error('URL is empty');
|
|
|
|
- error.nextBlockId = nextBlockId;
|
|
|
|
|
|
+ try {
|
|
|
|
+ if (isWhitespace(data.url)) throw new Error('url-empty');
|
|
|
|
+ if (!data.url.startsWith('http')) throw new Error('invalid-url');
|
|
|
|
|
|
- reject(error);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ await executeWebhook(data);
|
|
|
|
|
|
- if (!data.url.startsWith('http')) {
|
|
|
|
- const error = new Error('URL is not valid');
|
|
|
|
- error.nextBlockId = nextBlockId;
|
|
|
|
|
|
+ return {
|
|
|
|
+ data: '',
|
|
|
|
+ nextBlockId,
|
|
|
|
+ };
|
|
|
|
+ } catch (error) {
|
|
|
|
+ error.nextBlockId = nextBlockId;
|
|
|
|
|
|
- reject(error);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- executeWebhook(data)
|
|
|
|
- .then(() => {
|
|
|
|
- resolve({
|
|
|
|
- data: '',
|
|
|
|
- nextBlockId: getBlockConnection({ outputs }),
|
|
|
|
- });
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- reject(error);
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ throw error;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
export default webhook;
|
|
export default webhook;
|