Skip to content

Commit 4c5faef

Browse files
committed
More meaningful logging on failing requests to aw-server backend
1 parent 9715483 commit 4c5faef

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

main.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
PluginSettingTab,
77
request,
88
RequestUrlParam,
9-
Setting, TAbstractFile
9+
Setting,
10+
TAbstractFile
1011
} from 'obsidian';
1112
import * as os from "os";
1213

@@ -62,7 +63,13 @@ export default class ActivityWatchPlugin extends Plugin {
6263
}
6364

6465
async post(endpoint: string, data: object) {
65-
await request(new AWrequest(this.endpoint_url + endpoint, JSON.stringify(data)))
66+
const r = new AWrequest(this.endpoint_url + endpoint, JSON.stringify(data))
67+
try {
68+
await request(r)
69+
} catch (e) {
70+
console.log(`Request to URL [${r.url}] using [${r.method}], Header [${r.headers}], Body [${r.body}] failed!`)
71+
throw e
72+
}
6673
}
6774

6875
async createBucket(id: string, event_type: string) {
@@ -76,8 +83,7 @@ export default class ActivityWatchPlugin extends Plugin {
7683

7784
async sendHeartbeatData(id: string, heartbeat_data: object, pulsetime: number) {
7885
const endpoint = `buckets/${id}/heartbeat?pulsetime=${pulsetime}`
79-
const t = new Date().toISOString()
80-
await this.post(endpoint, {"timestamp": t, "duration": 0, "data": heartbeat_data})
86+
await this.post(endpoint, {"timestamp": new Date().toISOString(), "duration": 0, "data": heartbeat_data})
8187
}
8288

8389
async sendAbstractFileEvent(file: Nullable<TAbstractFile>, extraData: Nullable<object>, pulseTime: number) {
@@ -175,7 +181,7 @@ class ObsidianWatcherSettingTab extends PluginSettingTab {
175181
.setDesc('If enabled, uses development server for ActivityWatch instead of production. Default off.')
176182
.addToggle(t => t.setValue(this.plugin.settings.devServer)
177183
.onChange(async (value) => {
178-
console.log('Secret: ' + value);
184+
console.log(`switching plugin to use ${value ? "development" : "production"} backend`)
179185
this.plugin.settings.devServer = value;
180186
await this.plugin.saveSettings();
181187
await this.plugin.init()

0 commit comments

Comments
 (0)