mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 12:11:22 +00:00
Update fetcher to avoid parsing non-JSON responses
This commit is contained in:
parent
320fc0645d
commit
92bb7bcf51
@ -47,7 +47,18 @@ const createCustomizedFetchFetcher: CreateCustomizedFetchFetcher = (
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response: Response = await fetch(request)
|
const response: Response = await fetch(request)
|
||||||
const data = await response.json()
|
const responseContentType = response.headers.get('content-type')
|
||||||
|
let data
|
||||||
|
|
||||||
|
if (
|
||||||
|
!responseContentType ||
|
||||||
|
(!responseContentType.includes('application/json') &&
|
||||||
|
!responseContentType.includes('application/vnd.api+json'))
|
||||||
|
) {
|
||||||
|
data = await response.text()
|
||||||
|
} else {
|
||||||
|
data = await response.json()
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
// Use the "traditional" approach and reject non 2xx responses.
|
// Use the "traditional" approach and reject non 2xx responses.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user