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

DXCDT-550: Propagate errors through websocket connection #879

Merged

Conversation

sergiught
Copy link
Contributor

@sergiught sergiught commented Oct 16, 2023

🔧 Changes

This PR adds the ability to propagate errors through the WebSocket connection to the Web App used through the auth0 universal-login customize command. The payload of this message is as follows:

{
	"type": "ERROR",
	"payload": {
		"error": "information about what went wrong"
	}
}

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

h.shutdown()
return
}
defer func() {
_ = connection.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We weren't properly closing the connection before. This is really important to do.

Comment on lines +380 to +384
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) ||
websocket.IsUnexpectedCloseError(err, websocket.CloseAbnormalClosure) {
// The connection was closed.
break
}
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 logic is needed in order to prevent a panic where we keep trying to read from a closed connection due to the for loop.

@sergiught sergiught marked this pull request as ready for review October 16, 2023 14:25
@sergiught sergiught requested a review from a team as a code owner October 16, 2023 14:25

errorMsg := webSocketMessage{
Type: errorMessageType,
Payload: []byte(fmt.Sprintf(`{"error":%q}`, err.Error())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be using a struct to represent the error, and then JSON-encode it?

Copy link
Contributor Author

@sergiught sergiught Oct 16, 2023

Choose a reason for hiding this comment

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

Yep, we should. I plan to do that in a follow up PR and refactor the entire webSocketMessage so we can add custom JSON marshalling and unmarshalling and reuse the payload accordingly. This will prevent us from needing to unmarshal twice the message when we received it through the websocket as we're doing now.

The solution would be similar to what we do within the Go SDK for Connection Options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it is @Widcket -> #880


errorMsg := webSocketMessage{
Type: errorMessageType,
Payload: []byte(fmt.Sprintf(`{"error":%q}`, err.Error())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@sergiught sergiught requested a review from Widcket October 16, 2023 18:55
@sergiught sergiught merged commit 64c08a4 into feature/auth0-universal-login-customize Oct 17, 2023
6 checks passed
@sergiught sergiught deleted the DXCDT-550-propagate-errors branch October 17, 2023 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants