mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #3617 from overleaf/ae-fetch-json-data
Rename "responseBody" to "data" in fetchJSON error object GitOrigin-RevId: 75c166b23cbef22e82232f334ef373c66d9612a7
This commit is contained in:
@@ -49,35 +49,35 @@ function fetchJSON(
|
||||
|
||||
return fetch(path, options)
|
||||
.then(parseResponseBody)
|
||||
.then(({ responseBody, response }) => {
|
||||
.then(({ data, response }) => {
|
||||
if (!response.ok) {
|
||||
throw new OError(response.statusText, {
|
||||
statusCode: response.status,
|
||||
responseBody,
|
||||
data,
|
||||
response
|
||||
})
|
||||
}
|
||||
|
||||
return responseBody
|
||||
return data
|
||||
})
|
||||
}
|
||||
|
||||
function parseResponseBody(response) {
|
||||
const contentType = response.headers.get('Content-Type')
|
||||
if (/application\/json/.test(contentType)) {
|
||||
return response.json().then(json => {
|
||||
return { responseBody: json, response }
|
||||
return response.json().then(data => {
|
||||
return { data, response }
|
||||
})
|
||||
} else if (
|
||||
/text\/plain/.test(contentType) ||
|
||||
/text\/html/.test(contentType)
|
||||
) {
|
||||
return response.text().then(text => {
|
||||
return { responseBody: { message: text }, response }
|
||||
return { data: { message: text }, response }
|
||||
})
|
||||
} else {
|
||||
// response body ignored as content-type is either not set (e.g. 204
|
||||
// responses) or unsupported
|
||||
return Promise.resolve({ responseBody: {}, response })
|
||||
return Promise.resolve({ data: {}, response })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user