Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust error handling for auth elements for v2 api (TDX-3212) #117

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions cypress/e2e/specs/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,9 @@ describe('Login Page', () => {
cy.intercept('POST', '**/developer/authenticate', {
statusCode: 401,
body: {
errors: [
{
status: '401',
code: '1007',
title: 'Account is disabled',
detail: 'user account is disabled (#1007)'
}
]
status: 401,
title: "Developer is disabled",
detail: "Your account is disabled."
},
delay: 300
}).as('userAuthenticate')
Expand Down Expand Up @@ -200,13 +195,10 @@ describe('Login Page', () => {
cy.intercept('POST', '**/developer/verify-email', {
statusCode: 500,
body: {
errors: [
{
status: '500',
title: 'Internal Server Error',
detail: 'invalid status update request'
}
]
"status": 500,
"title": "Internal",
"instance": "konnect:trace:1158228726469534496",
"detail": "An internal failure occurred"
},
delay: 300
}).as('verifyEmailToken')
Expand All @@ -216,7 +208,7 @@ describe('Login Page', () => {
// returns to the login page
cy.location('pathname').should('equal', '/login')
cy.get('[data-testid="kong-auth-error-message"]')
.should('contain', 'Invalid status update request')
.should('contain', 'An internal failure occurred')

cy.get('input[id=email]').should('exist')
})
Expand Down
22 changes: 8 additions & 14 deletions cypress/e2e/specs/reset_password.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ describe('Reset Password Page', () => {
})
it('Errors out if reset token is invalid', () => {
cy.intercept('POST', '**/developer/reset-password', {
statusCode: 400,
statusCode: 500,
body:
{
errors: [
{
status: '400',
title: 'Invalid Token',
detail: 'The password reset token is invalid',
source: {
pointer: '/token'
}
}
]
},
{
"status": 500,
"title": "Internal",
"instance": "konnect:trace:1115722991246784904",
"detail": "An internal failure occurred"
},
delay: 300
}).as('resetPassword')

Expand All @@ -80,7 +74,7 @@ describe('Reset Password Page', () => {

cy.wait('@resetPassword').then(() => {
// Stays on the page as token is invalid
cy.get('[data-testid="kong-auth-error-message"]').should('contain', 'The password reset token is invalid')
cy.get('[data-testid="kong-auth-error-message"]').should('contain', 'An internal failure occurred')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is what's coming from KAuth - I think if we want a better message, it should be handled at KAuth's level since the API could theoretically throw a 500.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @kinman

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nateslo . This is a regression - the spec doesn't say we throw a 500 in this case, and we shouldn't. I'll make sure we have a test case for this.

cy.location('pathname').should('equal', '/reset-password')
})
})
Expand Down
15 changes: 3 additions & 12 deletions src/helpers/handleKongAuthElementsError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,9 @@ function handleKongAuthElementsError ({ error }) {
return validationErrors.join(', ')
}

const errors = error?.response?.data?.errors || []
if (errors.length === 1) {
const innerError = errors[0]

switch (innerError.code) {
case '1007':
return 'Your account is pending approval for access'
default:
return null
}
} else {
return null
const errorMsg = error?.response?.data || {}
if (errorMsg && errorMsg.title.includes('disabled')) {
return 'Your account is pending approval for access'
}
}
}
Expand Down