From 91ffc543b9557b3ad4e9ce4018247ae7308d4b52 Mon Sep 17 00:00:00 2001 From: Anil Erdogan Date: Fri, 24 Nov 2023 12:53:01 +0100 Subject: [PATCH] use `requestUrl` instead of `fetch --- main.ts | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/main.ts b/main.ts index 64be96c..957f058 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { App, Plugin, PluginSettingTab, Setting } from "obsidian"; +import { App, Plugin, PluginSettingTab, Setting, requestUrl } from "obsidian"; interface GChatReminderSettings { webhookUrl: string; @@ -8,7 +8,7 @@ const DEFAULT_SETTINGS: GChatReminderSettings = { webhookUrl: "", }; -export default class MyPlugin extends Plugin { +export default class GChatReminder extends Plugin { settings: GChatReminderSettings; notifiedTasks: Set = new Set(); @@ -122,22 +122,17 @@ export default class MyPlugin extends Plugin { }; try { - const response = await fetch( - `${webhookUrl}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(payload), - } - ); + const response = await requestUrl({ + method: "POST", + url: `${webhookUrl}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD`, + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }); - if (!response.ok) { - console.error( - "Error sending Google Chat Notifcation:", - response.statusText - ); + if (response.status != 200) { + console.error("Error sending Google Chat Notifcation:"); } } catch (error) { console.error("Error sending Google Chat Notifcation:", error); @@ -146,9 +141,9 @@ export default class MyPlugin extends Plugin { } class Settingstab extends PluginSettingTab { - plugin: MyPlugin; + plugin: GChatReminder; - constructor(app: App, plugin: MyPlugin) { + constructor(app: App, plugin: GChatReminder) { super(app, plugin); this.plugin = plugin; }