mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-13 19:37:37 -05:00
feat(http): add JSON parsing to httpApi data response
This commit is contained in:
@@ -27,7 +27,11 @@ export function useHttpApi(event: H3Event, token?: string): HttpApiFetch {
|
||||
if (response.statusCode >= 400) {
|
||||
const err = new Error(`Request failed with ${response.statusCode}`);
|
||||
try {
|
||||
(err as any).data = await response.body.text();
|
||||
if (response.headers['content-type']?.includes('application/json')) {
|
||||
(err as any).data = await response.body.json();
|
||||
} else {
|
||||
(err as any).data = await response.body.text();
|
||||
}
|
||||
} catch {
|
||||
// It's already errored, we don't need to know the body
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user