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?

Exception mapping is more suited for handling new types of exceptions.

Issues

Previous implementation was too tied with single type of backend response consisting of 'code', 'message' and 'label' fields.

Solutions

Add extendable interface in case we need to handle different payloads.


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 21, 2025 07:53
Comment on lines 33 to 46
val errorResponse = try {
this.response.body<ApiError>()
} catch (e: JsonConvertException) {
logger.error(
"HttpResponseValidator exception could not be mapped to any ApiError type; " +
"mapped as WireException.UnknownError. To handle this exception, " +
"extend the ApiError interface and update the mapper."
)
throw WireException.UnknownError(e.cause?.message, e)
}

throw when (this) {
is ClientRequestException -> {
WireException.ClientError(errorResponse, this)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I remember we said that mapToWireException was only used when dealing with BackendClient and therefore only dealt with Ktor based errors. Then we added the errorHandler (HttpResponseValidator) in Ktor config (which is nice).
If we map ktor exceptions, I don't think it makes sense to have here a generic mapper and try to deserialize or handle only Ktor errors.
I think we can do the simplest thing, remove this mapper completely and also ApiError and put all the ktor error handling inside HttpResponseValidator in the Modules.kt. In that file we map ktor exceptions to WireException, and if we know that Wire backend errors have a specific format (label and message), then we use that.

Instead of introducing ApiError, we can just subclass WireException.ClientError and create subclasses for specific issues.

@spoonman01 spoonman01 requested a review from Copilot July 21, 2025 13:38
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 exception handling by making the exception mapping more extensible and fixes a typo. The changes improve the interface design to handle different types of backend responses beyond the single standard format.

  • Renamed ErrorResponse to StandardError and moved MLS stale message logic to the response object
  • Refactored exception mapping to be more type-safe and extensible for different payload types
  • Fixed a spelling error in a test method name from "Unknow" to "Unknown"

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
WireExceptionMapper.kt Refactored mapping logic to be more type-safe and handle StandardError directly
WireException.kt Updated to use StandardError and removed duplicate MLS logic
StandardError.kt Renamed from ErrorResponse and added MLS stale message check method
Modules.kt Added proper type checking for ResponseException in validator
WireApplicationManager.kt Updated to use response.isMlsStaleMessage() method
HttpClientExceptionTest.kt Fixed typo and updated test to use response property


@Test
fun whenErrorResponseDoesNotContainLabelThenThrowUnknowException() {
fun whenErrorResponseDoesNotContainLabelThenThrowUnknownException() {
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

Fixed spelling error: 'Unknow' corrected to 'Unknown' in the test method name.

Copilot uses AI. Check for mistakes.

@MarianKijewski MarianKijewski merged commit 88f76be into main Jul 21, 2025
2 checks passed
@MarianKijewski MarianKijewski deleted the chore/WPB-18240-fix-typo-and-refactor branch July 21, 2025 13:48
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