Skip to content

Conversation

MarianKijewski
Copy link
Contributor


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

Not possible to specify exactly what HTTP exception indicates

Causes

Standard exceptions were mapped into custom Wire exception without exposing additional information

Solutions

  • Map error response to serialized data class that holds label of the exception using native Ktor HTTP response validator
  • Remove custom mapper

Testing

Test Coverage

  • I have added automated test to this contribution

PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

@MarianKijewski MarianKijewski requested a review from a team as a code owner July 15, 2025 11:01
Copy link
Member

@alexandreferris alexandreferris left a comment

Choose a reason for hiding this comment

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

Great work! I just added some nitpick comments but overall super great! now we have better handling of exceptions 🙌🏻

@MarianKijewski MarianKijewski merged commit a62b136 into main Jul 15, 2025
2 checks passed
@MarianKijewski MarianKijewski deleted the feat/WPB-18240_handle_mls_http_exceptions branch July 15, 2025 15:16
@MarianKijewski MarianKijewski requested a review from Copilot July 15, 2025 15:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors HTTP exception handling to provide more specific error information, particularly for MLS (Message Layer Security) HTTP exceptions. The changes replace a generic exception mapping approach with a structured response validator that can identify specific error types through response labels.

Key changes:

  • Implemented native Ktor HTTP response validation for better error handling granularity
  • Added structured error response mapping with label-based exception identification
  • Replaced generic HTTP status code checking with specific label-based exception detection for MLS stale message errors

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
WireExceptionMapperTest.kt Removed old generic exception mapping tests
HttpClientExceptionTest.kt Added comprehensive tests for new HTTP response validation with MLS-specific error scenarios
WireApplicationManager.kt Updated to use label-based MLS stale message detection instead of HTTP status code
ErrorResponse.kt New data class for structured error response parsing
WireExceptionMapper.kt Refactored to handle Ktor ResponseException with structured error response parsing
WireException.kt Updated ClientError and InternalSystemError to use ErrorResponse with MLS-specific helper methods
NetworkErrorLabel.kt Added constants for network error labels
Modules.kt Integrated new HTTP response validator into HttpClient configuration
BackendClientImpl.kt Removed generic exception wrapper calls
BackendClientDemo.kt Removed generic exception wrapper calls and updated exception handling

}

@Test
fun whenErrorResponseDoesNotContainLabelThenThrowUnknowException() {
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Function name contains a spelling error: 'Unknow' should be 'Unknown'

Suggested change
fun whenErrorResponseDoesNotContainLabelThenThrowUnknowException() {
fun whenErrorResponseDoesNotContainLabelThenThrowUnknownException() {

Copilot uses AI. Check for mistakes.

)
else -> WireException.UnknownError(throwable = this)
}
suspend fun Throwable.mapToWireException() {
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

The function returns Unit but always throws an exception. Consider changing the return type to Nothing to make the non-returning behavior explicit

Suggested change
suspend fun Throwable.mapToWireException() {
suspend fun Throwable.mapToWireException(): Nothing {

Copilot uses AI. Check for mistakes.

throwable = this
)
}
} catch (_: JsonConvertException) {
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Consider logging the JsonConvertException before falling back to UnknownError to aid in debugging serialization issues

Suggested change
} catch (_: JsonConvertException) {
} catch (e: JsonConvertException) {
logger.error("JsonConvertException occurred while processing the response: ${e.message}", e)

Copilot uses AI. Check for mistakes.

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