-
Notifications
You must be signed in to change notification settings - Fork 61
Fix: #676 Handle text/plain response content type correctly #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
51d3663
a81db18
7922d34
d867584
fc9c6d3
dbc2713
353f02e
1771c2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,24 @@ async function DefaultResponseProcess(response: any) { | |
| throw new Error("Unauthenticated") | ||
| } | ||
|
|
||
| const message = await response.json().then((data: any) => data.message) | ||
| throw new Error(message) | ||
| } else { | ||
| return response.json() | ||
| try { | ||
| const message = await response.json().then((data: any) => data.message) | ||
| throw new Error(message) | ||
| } catch { | ||
| const text = await response.text() | ||
| throw new Error(text) | ||
| } | ||
| } | ||
|
|
||
| const contentType = response.headers.get('Content-Type') || ''; | ||
| if (contentType.startsWith('text/plain')) { | ||
| return response.text(); | ||
|
||
| } | ||
| try { | ||
| return await response.json(); | ||
| } catch (e) { | ||
| // If JSON parsing fails, return as text | ||
| return response.text(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code will always run to here due to line 37.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢