Handle webhook errors (#9715)
This commit is contained in:
parent
054175a127
commit
8fe0cdf89f
4 changed files with 111 additions and 47 deletions
|
@ -67,17 +67,33 @@ 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) {
|
||||||
method: "post",
|
return {
|
||||||
body: JSON.stringify({
|
httpStatus: 400,
|
||||||
username,
|
response: "Missing Webhook URL",
|
||||||
avatar_url,
|
success: false,
|
||||||
content,
|
}
|
||||||
}),
|
}
|
||||||
headers: {
|
let response
|
||||||
"Content-Type": "application/json",
|
try {
|
||||||
},
|
response = await fetch(url, {
|
||||||
})
|
method: "post",
|
||||||
|
body: JSON.stringify({
|
||||||
|
username,
|
||||||
|
avatar_url,
|
||||||
|
content,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"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 {
|
||||||
|
|
|
@ -69,19 +69,35 @@ 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) {
|
||||||
method: "post",
|
return {
|
||||||
body: JSON.stringify({
|
httpStatus: 400,
|
||||||
value1,
|
response: "Missing Webhook URL",
|
||||||
value2,
|
success: false,
|
||||||
value3,
|
}
|
||||||
value4,
|
}
|
||||||
value5,
|
let response
|
||||||
}),
|
try {
|
||||||
headers: {
|
response = await fetch(url, {
|
||||||
"Content-Type": "application/json",
|
method: "post",
|
||||||
},
|
body: JSON.stringify({
|
||||||
})
|
value1,
|
||||||
|
value2,
|
||||||
|
value3,
|
||||||
|
value4,
|
||||||
|
value5,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"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 {
|
||||||
|
|
|
@ -50,15 +50,31 @@ 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) {
|
||||||
method: "post",
|
return {
|
||||||
body: JSON.stringify({
|
httpStatus: 400,
|
||||||
text,
|
response: "Missing Webhook URL",
|
||||||
}),
|
success: false,
|
||||||
headers: {
|
}
|
||||||
"Content-Type": "application/json",
|
}
|
||||||
},
|
let response
|
||||||
})
|
try {
|
||||||
|
response = await fetch(url, {
|
||||||
|
method: "post",
|
||||||
|
body: JSON.stringify({
|
||||||
|
text,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"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 {
|
||||||
|
|
|
@ -63,22 +63,38 @@ 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
|
||||||
method: "post",
|
try {
|
||||||
body: JSON.stringify({
|
response = await fetch(url, {
|
||||||
platform: "budibase",
|
method: "post",
|
||||||
value1,
|
body: JSON.stringify({
|
||||||
value2,
|
platform: "budibase",
|
||||||
value3,
|
value1,
|
||||||
value4,
|
value2,
|
||||||
value5,
|
value3,
|
||||||
}),
|
value4,
|
||||||
headers: {
|
value5,
|
||||||
"Content-Type": "application/json",
|
}),
|
||||||
},
|
headers: {
|
||||||
})
|
"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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue