Merge pull request #14565 from overleaf/jpa-add-error-context

[web] add response context to errors of failed logout/login action in CI

GitOrigin-RevId: 9b2e23e243541f87476f8cc71687f9492f615b4d
This commit is contained in:
Jakob Ackermann 2023-08-29 19:12:28 +02:00 committed by Copybot
parent 6b61d906ba
commit 3d9e9f6aeb

View file

@ -142,7 +142,14 @@ class UserHelper {
response.status !== 302 || response.status !== 302 ||
!response.headers.get('location').includes('/login') !response.headers.get('location').includes('/login')
) { ) {
throw new Error('logout failed') const body = await response.text()
throw new Error(
`logout failed: status=${response.status} body=${JSON.stringify(
body
)} headers=${JSON.stringify(
Object.fromEntries(response.headers.entries())
)}`
)
} }
// after logout CSRF token becomes invalid // after logout CSRF token becomes invalid
this._csrfToken = '' this._csrfToken = ''
@ -258,14 +265,21 @@ class UserHelper {
}), }),
}) })
if (!response.ok) { if (!response.ok) {
const error = new Error('login failed') const body = await response.text()
const error = new Error(
`login failed: status=${response.status} body=${JSON.stringify(body)}`
)
error.response = response error.response = response
throw error throw error
} }
const body = await response.json() const body = await response.json()
if (body.redir !== '/project') { if (body.redir !== '/project') {
const error = new Error('login failed') const error = new Error(
`login should redirect to /project: status=${
response.status
} body=${JSON.stringify(body)}`
)
error.response = response error.response = response
throw error throw error
} }