Skip to content

Commit

Permalink
Handle webhook errors (Budibase#9715)
Browse files Browse the repository at this point in the history
  • Loading branch information
melohagan authored Feb 16, 2023
1 parent deceabf commit 02ed5fd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 47 deletions.
38 changes: 27 additions & 11 deletions packages/server/src/automations/steps/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,33 @@ export async function run({ inputs }: AutomationStepInput) {
if (!avatar_url) {
avatar_url = DEFAULT_AVATAR_URL
}
const response = await fetch(url, {
method: "post",
body: JSON.stringify({
username,
avatar_url,
content,
}),
headers: {
"Content-Type": "application/json",
},
})
if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
let response
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)
return {
Expand Down
42 changes: 29 additions & 13 deletions packages/server/src/automations/steps/integromat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,35 @@ export const definition: AutomationStepSchema = {
export async function run({ inputs }: AutomationStepInput) {
const { url, value1, value2, value3, value4, value5 } = inputs

const response = await fetch(url, {
method: "post",
body: JSON.stringify({
value1,
value2,
value3,
value4,
value5,
}),
headers: {
"Content-Type": "application/json",
},
})
if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
let response
try {
response = await fetch(url, {
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)
return {
Expand Down
34 changes: 25 additions & 9 deletions packages/server/src/automations/steps/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,31 @@ export const definition: AutomationStepSchema = {

export async function run({ inputs }: AutomationStepInput) {
let { url, text } = inputs
const response = await fetch(url, {
method: "post",
body: JSON.stringify({
text,
}),
headers: {
"Content-Type": "application/json",
},
})
if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
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)
return {
Expand Down
44 changes: 30 additions & 14 deletions packages/server/src/automations/steps/zapier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,38 @@ export const definition: AutomationStepSchema = {
export async function run({ inputs }: AutomationStepInput) {
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
// if no values supplied
const response = await fetch(url, {
method: "post",
body: JSON.stringify({
platform: "budibase",
value1,
value2,
value3,
value4,
value5,
}),
headers: {
"Content-Type": "application/json",
},
})
let response
try {
response = await fetch(url, {
method: "post",
body: JSON.stringify({
platform: "budibase",
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)

Expand Down

0 comments on commit 02ed5fd

Please sign in to comment.