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

Improve the memory and performance handling delivery response status codes #1558

Merged
merged 1 commit into from
Dec 14, 2021
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## TBD

### Enhancements

* Improve the memory use and performance overhead when handling the delivery response status codes
[#1558](https://github.com/bugsnag/bugsnag-android/pull/1558)

## 5.17.0 (2021-12-08)

### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ internal class DefaultDelivery(
}

internal fun getDeliveryStatus(responseCode: Int): DeliveryStatus {
val unrecoverableCodes = IntRange(HTTP_BAD_REQUEST, 499).filter {
it != HTTP_CLIENT_TIMEOUT && it != 429
}

return when (responseCode) {
in HTTP_OK..299 -> DeliveryStatus.DELIVERED
in unrecoverableCodes -> DeliveryStatus.FAILURE
return when {
responseCode in HTTP_OK..299 -> DeliveryStatus.DELIVERED
isUnrecoverableStatusCode(responseCode) -> DeliveryStatus.FAILURE
else -> DeliveryStatus.UNDELIVERED
}
}

private fun isUnrecoverableStatusCode(responseCode: Int) =
responseCode in HTTP_BAD_REQUEST..499 && // 400-499 are considered unrecoverable
responseCode != HTTP_CLIENT_TIMEOUT && // except for 408
responseCode != 429 // and 429
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ class DeliveryTest {
assertEquals(DeliveryStatus.UNDELIVERED, delivery.getDeliveryStatus(408))
assertEquals(DeliveryStatus.UNDELIVERED, delivery.getDeliveryStatus(429))
assertEquals(DeliveryStatus.FAILURE, delivery.getDeliveryStatus(400))
assertEquals(DeliveryStatus.FAILURE, delivery.getDeliveryStatus(401))
assertEquals(DeliveryStatus.FAILURE, delivery.getDeliveryStatus(498))
assertEquals(DeliveryStatus.FAILURE, delivery.getDeliveryStatus(499))
assertEquals(DeliveryStatus.UNDELIVERED, delivery.getDeliveryStatus(408))
assertEquals(DeliveryStatus.UNDELIVERED, delivery.getDeliveryStatus(429))
}
}