mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-30 00:48:36 +08:00
use json to parse the error information
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { App, Notice, requestUrl, TFile } from "obsidian";
|
import {App, Notice, requestUrl, TFile} from "obsidian";
|
||||||
import { markdownToBlocks } from "@tryfabric/martian";
|
import { markdownToBlocks } from "@tryfabric/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
// import * as yaml from "yaml"
|
||||||
@@ -6,6 +6,7 @@ import MyPlugin from "src/main";
|
|||||||
import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
|
import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
|
||||||
import { updateYamlInfo } from "../updateYaml";
|
import { updateYamlInfo } from "../updateYaml";
|
||||||
import { UploadBaseCustom } from "./BaseUpload2NotionCustom";
|
import { UploadBaseCustom } from "./BaseUpload2NotionCustom";
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
export class Upload2NotionCustom extends UploadBaseCustom {
|
export class Upload2NotionCustom extends UploadBaseCustom {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
@@ -74,21 +75,19 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await requestUrl({
|
await fetch("https://api.notion.com/v1/pages", {
|
||||||
url: `https://api.notion.com/v1/pages`,
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
// 'User-Agent': 'obsidian.md',
|
"Authorization": "Bearer " + notionAPI,
|
||||||
Authorization:
|
|
||||||
"Bearer " + notionAPI,
|
|
||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
})
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
new Notice(`network error ${error}`);
|
console.log(JSON.stringify(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotionCustom(
|
async syncMarkdownToNotionCustom(
|
||||||
@@ -124,6 +123,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
} else {
|
} else {
|
||||||
res = await this.createPage(cover, customValues, file2Block);
|
res = await this.createPage(cover, customValues, file2Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res && res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user