Skip to content

Commit

Permalink
perf(delivery): improve the memory and performance overhead of handli…
Browse files Browse the repository at this point in the history
…ng the delivery response status code
  • Loading branch information
lemnik committed Dec 14, 2021
1 parent 9807e53 commit bd276d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
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))
}
}

0 comments on commit bd276d5

Please sign in to comment.