Skip to content

Commit

Permalink
Added detailed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Feb 19, 2023
1 parent a51f4d0 commit 50eb1e9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/commands/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,27 @@ export default class Custom extends Command {
body = JSON.stringify(trigger.body);
headers["content-type"] = "application/json";
}
const r = new Request(trigger.url, {
url = new Request(trigger.url, {
method: trigger.method ?? "POST",
headers,
body
});
url = r;
}
// trigger should be GET
const fp = typeof url !== "object" ? url : JSON.stringify({
url: url.url,
body: url.body,
headers: !url.headers ? null : Object.fromEntries(url.headers.entries())
});
try {
const rs = await fetch(url);
if(rs.status <= 300) {
return `Trigger invoked ${typeof trigger === "object" ? JSON.stringify(trigger) : trigger} successfully.`;
return `Trigger invoked ${fp} successfully.`;
}
throw new Error(`Failed ${await rs.text()}`);
throw new Error(`${await rs.text()}`);
} catch (e) {
console.error(e);
return `Trigger invoke ${url} failed ${e.stack ? e.stack : e}.`;
return `Trigger invoke ${fp} failed ${e.stack ? e.stack : e}.`;
}
}

Expand Down

0 comments on commit 50eb1e9

Please sign in to comment.