updated logging for API calls

This commit is contained in:
Viet Huynh
2023-11-02 02:42:28 +07:00
parent 6f1ba625c0
commit ac535c927a
5 changed files with 44 additions and 24 deletions
+33 -20
View File
@@ -62,7 +62,6 @@ export const createZeroTrustListsOneByOne = async (items) => {
* @param {string[]} items The domains.
*/
export const createZeroTrustListsAtOnce = async (items) => {
const totalListNumber = Math.ceil(items.length / LIST_ITEM_SIZE);
const requests = [];
for (let i = 0, listNumber = 1; i < items.length; i += LIST_ITEM_SIZE) {
@@ -77,7 +76,7 @@ export const createZeroTrustListsAtOnce = async (items) => {
try {
await Promise.all(requests);
console.log(`Created ${totalListNumber} lists`);
console.log("Created lists successfully");
} catch (err) {
console.error(`Error occurred while creating lists - ${err.toString()}`);
}
@@ -125,7 +124,7 @@ export const deleteZeroTrustListsAtOnce = async (lists) => {
try {
await Promise.all(requests);
console.log(`Deleted ${lists.length} lists`);
console.log("Deleted lists successfully");
} catch (err) {
console.error(`Error occurred while deleting lists - ${err.toString()}`);
}
@@ -147,19 +146,26 @@ export const getZeroTrustRules = () =>
* @param {string} wirefilterExpression The expression to be used for the rule.
* @returns {Promise<Object>}
*/
export const createZeroTrustRule = (wirefilterExpression) =>
requestGateway("/rules", {
method: "POST",
body: JSON.stringify({
name: "CGPS Filter Lists",
description:
"Filter lists created by Cloudflare Gateway Pi-hole Scripts. Avoid editing this rule. Changing the name of this rule will break the script.",
enabled: true,
action: "block",
filters: ["dns"],
traffic: wirefilterExpression,
}),
});
export const createZeroTrustRule = async (wirefilterExpression) => {
try {
await requestGateway("/rules", {
method: "POST",
body: JSON.stringify({
name: "CGPS Filter Lists",
description:
"Filter lists created by Cloudflare Gateway Pi-hole Scripts. Avoid editing this rule. Changing the name of this rule will break the script.",
enabled: true,
action: "block",
filters: ["dns"],
traffic: wirefilterExpression,
}),
});
console.log("Created rule successfully");
} catch (err) {
console.error(`Error occurred while creating rule - ${err.toString()}`);
}
};
/**
* Deletes a Zero Trust rule.
@@ -168,7 +174,14 @@ export const createZeroTrustRule = (wirefilterExpression) =>
* @param {number} id The ID of the rule to be deleted.
* @returns {Promise<Object>}
*/
export const deleteZeroTrustRule = (id) =>
requestGateway(`/rules/${id}`, {
method: "DELETE",
});
export const deleteZeroTrustRule = async (id) => {
try {
await requestGateway(`/rules/${id}`, {
method: "DELETE",
});
console.log("Deleted rule successfully");
} catch (err) {
console.error(`Error occurred while deleting rule - ${err.toString()}`);
}
};