Skip to content

Commit

Permalink
try catch isn't always the way
Browse files Browse the repository at this point in the history
  • Loading branch information
CubesterYT committed Jan 20, 2025
1 parent 411295c commit 99fd522
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions extensions/CubesterYT/Webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,42 +210,41 @@
Scratch.vm.extensionManager.refreshBlocks("cubesterWebhooks");
}
data(args) {
try {
switch (webhooks[args.WEBHOOK].TYPE) {
case "application/x-www-form-urlencoded":
return toForm(webhooks[args.WEBHOOK].DATA);
default:
return JSON.stringify(webhooks[args.WEBHOOK].DATA);
}
} catch (error) {
if (!webhooks[args.WEBHOOK]) {
return "";
}
switch (webhooks[args.WEBHOOK].TYPE) {
case "application/x-www-form-urlencoded":
return toForm(webhooks[args.WEBHOOK].DATA);
default:
return JSON.stringify(webhooks[args.WEBHOOK].DATA);
}
}
setData(args) {
if (!webhooks[args.WEBHOOK]) {
return;
}
try {
webhooks[args.WEBHOOK].DATA = JSON.parse(
Scratch.Cast.toString(args.JSON)
);
webhooks[args.WEBHOOK].TYPE = args.TYPE;
} catch (error) {
return;
}
} catch (error) {}
webhooks[args.WEBHOOK].TYPE = args.TYPE;
}
postData(args) {
try {
Scratch.fetch(webhooks[args.WEBHOOK].URL, {
method: "POST",
headers: {
"Content-type": webhooks[args.WEBHOOK].TYPE,
},
body:
webhooks[args.WEBHOOK].TYPE === "application/json"
? JSON.stringify(webhooks[args.WEBHOOK].DATA)
: toForm(webhooks[args.WEBHOOK].DATA),
});
} catch (error) {
if (!webhooks[args.WEBHOOK]) {
return;
}
Scratch.fetch(webhooks[args.WEBHOOK].URL, {
method: "POST",
headers: {
"Content-type": webhooks[args.WEBHOOK].TYPE,
},
body:
webhooks[args.WEBHOOK].TYPE === "application/json"
? JSON.stringify(webhooks[args.WEBHOOK].DATA)
: toForm(webhooks[args.WEBHOOK].DATA),
});
}

_webhookMenu() {
Expand Down

0 comments on commit 99fd522

Please sign in to comment.