Skip to content

Commit 85b95fa

Browse files
GoBeromsuclaude
andcommitted
fix: use fetch API for streaming requests to enable error body reading
Obsidian's requestUrl throws on 4xx errors, making it impossible to read the error response body. Switching to native fetch API allows proper error handling and debugging of Codex API 400 errors. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c62d8ea commit 85b95fa

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "metadata-auto-classifier",
33
"name": "Metadata Auto Classifier",
4-
"version": "1.9.6",
4+
"version": "1.9.7",
55
"minAppVersion": "0.15.0",
66
"description": "Automatically classifies and applies metadata to your notes.",
77
"author": "Beomsu Koh",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metadata-auto-classifier",
3-
"version": "1.9.6",
3+
"version": "1.9.7",
44
"description": "Metadata Auto Classifier is an innovative Obsidian plugin that harnesses the power of AI to revolutionize your note-taking experience. By automatically generating and classifying metadata for your notes, this plugin streamlines your workflow and enhances the organization of your knowledge base.",
55
"main": "main.js",
66
"scripts": {

src/provider/request.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const parseSSEEvents = (text: string): SSEEvent[] => {
107107
/**
108108
* Send a streaming request and accumulate text from SSE events
109109
* Uses provider-specific event parser to extract text deltas
110+
* Uses fetch API instead of Obsidian's requestUrl for better error handling
110111
*/
111112
export const sendStreamingRequest = async (
112113
url: string,
@@ -124,8 +125,9 @@ export const sendStreamingRequest = async (
124125
body,
125126
});
126127

127-
const response = await requestUrl({
128-
url,
128+
// Use fetch instead of Obsidian's requestUrl for better error handling
129+
// requestUrl throws on 4xx errors, making it impossible to read error body
130+
const response = await fetch(url, {
129131
method: 'POST',
130132
headers: {
131133
...headers,
@@ -134,17 +136,20 @@ export const sendStreamingRequest = async (
134136
body: JSON.stringify(body),
135137
});
136138

137-
if (response.status >= 400) {
139+
if (!response.ok) {
140+
const errorText = await response.text();
138141
console.error('[API Streaming Error]', {
139142
status: response.status,
140143
url,
141-
responseText: response.text,
144+
responseText: errorText,
142145
});
143-
throw new Error(`Streaming request failed (HTTP ${response.status}): ${response.text}`);
146+
throw new Error(`Streaming request failed (HTTP ${response.status}): ${errorText}`);
144147
}
145148

149+
const responseText = await response.text();
150+
146151
// Parse SSE events from response text
147-
const events = parseSSEEvents(response.text);
152+
const events = parseSSEEvents(responseText);
148153
let accumulatedText = '';
149154

150155
for (const event of events) {

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@
8080
"1.9.3": "0.15.0",
8181
"1.9.4": "0.15.0",
8282
"1.9.5": "0.15.0",
83-
"1.9.6": "0.15.0"
83+
"1.9.6": "0.15.0",
84+
"1.9.7": "0.15.0"
8485
}

0 commit comments

Comments
 (0)