Skip to content

Commit c71d30d

Browse files
committed
fix using NetworkUtils response type
1 parent 734877c commit c71d30d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/outcomes/impl/OutcomeEventsController.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.onesignal.session.internal.outcomes.impl
22

33
import android.os.Process
4+
import com.onesignal.common.NetworkUtils
45
import com.onesignal.common.exceptions.BackendException
56
import com.onesignal.common.threading.suspendifyOnThread
67
import com.onesignal.core.internal.config.ConfigModelStore
@@ -226,18 +227,18 @@ Outcome event was cached and will be reattempted on app cold start""",
226227
// The only case where an actual success has occurred and the OutcomeEvent should be sent back
227228
return OutcomeEvent.fromOutcomeEventParamstoOutcomeEvent(eventParams)
228229
} catch (ex: BackendException) {
229-
if (ex.statusCode == HttpURLConnection.HTTP_BAD_REQUEST) {
230-
Logging.error("400 error sending outcome event, omitting further retries!")
231-
_outcomeEventsCache.deleteOldOutcomeEvent(eventParams)
232-
} else {
233-
Logging.warn(
234-
"""OutcomeEventsController.sendAndCreateOutcomeEvent: Sending outcome with name: $name failed with status code: ${ex.statusCode} and response: ${ex.response}
235-
Outcome event was cached and will be reattempted on app cold start""",
236-
)
230+
val responseType = NetworkUtils.getResponseStatusType(ex.statusCode)
231+
val err = "OutcomeEventsController.sendAndCreateOutcomeEvent: Sending outcome with name: $name failed with status code: ${ex.statusCode} and response: ${ex.response}"
232+
233+
if (responseType == NetworkUtils.ResponseStatusType.RETRYABLE) {
234+
Logging.warn("$err Outcome event was cached and will be reattempted on app cold start")
237235

238236
// Only if we need to save and retry the outcome, then we will save the timestamp for future sending
239237
eventParams.timestamp = timestampSeconds
240238
_outcomeEventsCache.saveOutcomeEvent(eventParams)
239+
} else {
240+
Logging.error("$err Outcome event will be omitted!")
241+
_outcomeEventsCache.deleteOldOutcomeEvent(eventParams)
241242
}
242243

243244
// Return null to determine not a failure, but not a success in terms of the request made

0 commit comments

Comments
 (0)