[web] In _deleteV1Account: Add response?.statusCode optional chaining, await request before getting response (#19936)

* Add optional chaining in `response.statusCode` in `_deleteV1Account` error handling

Should fix https://overleaf.sentry.io/issues/5708988236/

* Add another `response?.statusCode`

* Await `V1Api.promises.request` before getting the response

GitOrigin-RevId: 52a156680845516357b11943bee8c33a5a023514
This commit is contained in:
Antoine Clausse 2024-08-14 10:23:48 +02:00 committed by Copybot
parent 019562cb5a
commit 8e68f10523

View file

@ -71,17 +71,17 @@ const V1Api = {
)
}
if (
(response.statusCode >= 200 && response.statusCode < 300) ||
(response && response.statusCode >= 200 && response.statusCode < 300) ||
Array.from(options.expectedStatusCodes || []).includes(
response.statusCode
response?.statusCode
)
) {
return callback(null, response, body)
} else if (response.statusCode === 403) {
} else if (response?.statusCode === 403) {
error = new Errors.ForbiddenError('overleaf v1 returned forbidden')
error.statusCode = response.statusCode
return callback(error)
} else if (response.statusCode === 404) {
} else if (response?.statusCode === 404) {
error = new Errors.NotFoundError(
`overleaf v1 returned non-success code: ${response.statusCode} ${options.method} ${options.uri}`
)
@ -89,9 +89,9 @@ const V1Api = {
return callback(error)
} else {
error = new Error(
`overleaf v1 returned non-success code: ${response.statusCode} ${options.method} ${options.uri}`
`overleaf v1 returned non-success code: ${response?.statusCode} ${options.method} ${options.uri}`
)
error.statusCode = response.statusCode
error.statusCode = response?.statusCode
return callback(error)
}
},