1
0
Fork 0
mirror of synced 2024-08-15 01:51:33 +12:00

Handle webhook errors (#9715)

This commit is contained in:
melohagan 2023-02-16 16:23:44 +00:00 committed by GitHub
parent 054175a127
commit 8fe0cdf89f
4 changed files with 111 additions and 47 deletions

View file

@ -67,7 +67,16 @@ export async function run({ inputs }: AutomationStepInput) {
if (!avatar_url) { if (!avatar_url) {
avatar_url = DEFAULT_AVATAR_URL avatar_url = DEFAULT_AVATAR_URL
} }
const response = await fetch(url, { if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
let response
try {
response = await fetch(url, {
method: "post", method: "post",
body: JSON.stringify({ body: JSON.stringify({
username, username,
@ -78,6 +87,13 @@ export async function run({ inputs }: AutomationStepInput) {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}) })
} catch (err: any) {
return {
httpStatus: 400,
response: err.message,
success: false,
}
}
const { status, message } = await getFetchResponse(response) const { status, message } = await getFetchResponse(response)
return { return {

View file

@ -69,7 +69,16 @@ export const definition: AutomationStepSchema = {
export async function run({ inputs }: AutomationStepInput) { export async function run({ inputs }: AutomationStepInput) {
const { url, value1, value2, value3, value4, value5 } = inputs const { url, value1, value2, value3, value4, value5 } = inputs
const response = await fetch(url, { if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
let response
try {
response = await fetch(url, {
method: "post", method: "post",
body: JSON.stringify({ body: JSON.stringify({
value1, value1,
@ -82,6 +91,13 @@ export async function run({ inputs }: AutomationStepInput) {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}) })
} catch (err: any) {
return {
httpStatus: 400,
response: err.message,
success: false,
}
}
const { status, message } = await getFetchResponse(response) const { status, message } = await getFetchResponse(response)
return { return {

View file

@ -50,7 +50,16 @@ export const definition: AutomationStepSchema = {
export async function run({ inputs }: AutomationStepInput) { export async function run({ inputs }: AutomationStepInput) {
let { url, text } = inputs let { url, text } = inputs
const response = await fetch(url, { if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
let response
try {
response = await fetch(url, {
method: "post", method: "post",
body: JSON.stringify({ body: JSON.stringify({
text, text,
@ -59,6 +68,13 @@ export async function run({ inputs }: AutomationStepInput) {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}) })
} catch (err: any) {
return {
httpStatus: 400,
response: err.message,
success: false,
}
}
const { status, message } = await getFetchResponse(response) const { status, message } = await getFetchResponse(response)
return { return {

View file

@ -63,9 +63,18 @@ export const definition: AutomationStepSchema = {
export async function run({ inputs }: AutomationStepInput) { export async function run({ inputs }: AutomationStepInput) {
const { url, value1, value2, value3, value4, value5 } = inputs const { url, value1, value2, value3, value4, value5 } = inputs
if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
// send the platform to make sure zaps always work, even // send the platform to make sure zaps always work, even
// if no values supplied // if no values supplied
const response = await fetch(url, { let response
try {
response = await fetch(url, {
method: "post", method: "post",
body: JSON.stringify({ body: JSON.stringify({
platform: "budibase", platform: "budibase",
@ -79,6 +88,13 @@ export async function run({ inputs }: AutomationStepInput) {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}) })
} catch (err: any) {
return {
httpStatus: 400,
response: err.message,
success: false,
}
}
const { status, message } = await getFetchResponse(response) const { status, message } = await getFetchResponse(response)