Skip to content

Commit

Permalink
replaced fetch with requestUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-baumberger committed Oct 20, 2023
1 parent 08e5200 commit 2a7fe63
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {jsonToTable, tableToJson} from "src/functions";
import {Editor, Notice, Plugin} from "obsidian";
import {Editor, Notice, Plugin, requestUrl} from "obsidian";
import {JsonTablePluginSettingTab} from "src/settings";

interface JsonTablePluginSettings {
Expand Down Expand Up @@ -39,19 +39,23 @@ export default class JsonTablePlugin extends Plugin {
icon: "link",
editorCallback: async (editor: Editor) => {
const selection = editor.getSelection();
const response = await fetch(selection);

if (!response.ok) {
console.error(response.statusText);
new Notice(response.statusText);
}

const json = await response.json();
try {
const response = await requestUrl(selection);

editor.replaceSelection(jsonToTable(JSON.stringify(json)));
editor.replaceSelection(
jsonToTable(JSON.stringify(response.json))
);

if (this.settings.devMode) {
console.log("JSON Table fetch response:", json);
if (this.settings.devMode) {
console.log(
"JSON Table fetch response:",
response.json
);
}
} catch (error) {
console.error(error);
new Notice(error);
}
}
});
Expand Down

0 comments on commit 2a7fe63

Please sign in to comment.