Compare commits

..

No commits in common. "5a50db714f60571cb0a4936af9b97df2d9aab259" and "940f190eac451c7596612bea31d55e84a47055b7" have entirely different histories.

View file

@ -66,7 +66,7 @@ export const paramsString = (params = {}) => {
)
}
export const promisedRequest = async ({
export const promisedRequest = ({
method,
url,
params,
@ -107,41 +107,47 @@ export const promisedRequest = async ({
}
}
const response = await fetch(url, options)
return fetch(url, options).then((response) => {
return new Promise((resolve, reject) => {
// 204 is "No content", which fails to parse json (as you'd might think)
if (response.ok && response.status === 204) resolve()
// 204 is "No content", which fails to parse json (as you'd might think)
if (response.ok && response.status === 204) return { _response: response }
return response
.json()
.then((json) => {
if (!response.ok) {
return reject(
new StatusCodeError(
response.status,
json,
{ url, options },
response,
),
)
}
if (!response.ok) {
throw new StatusCodeError(
response.status,
json,
{ url, options },
response,
)
}
if (typeof json !== 'object') {
return resolve({
_response: response,
_value: json,
})
}
json._response = response
try {
const json = await response.json()
if (typeof json !== 'object') {
return {
_response: response,
_value: json,
}
}
json._response = response
return json
} catch (error) {
throw new StatusCodeError(
response.status,
error,
{ url, options },
response,
)
}
return resolve(json)
})
.catch((error) => {
return reject(
new StatusCodeError(
response.status,
error,
{ url, options },
response,
),
)
})
})
})
}
const authHeaders = (accessToken) => {