-
Notifications
You must be signed in to change notification settings - Fork 1
/
SRGErrorMessageProvider.kt
54 lines (45 loc) · 1.81 KB
/
SRGErrorMessageProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.core.business
import android.content.Context
import android.util.Pair
import androidx.media3.common.ErrorMessageProvider
import androidx.media3.common.PlaybackException
import androidx.media3.datasource.DataSourceException
import ch.srgssr.pillarbox.core.business.exception.BlockReasonException
import ch.srgssr.pillarbox.core.business.exception.DataParsingException
import ch.srgssr.pillarbox.core.business.exception.ResourceNotFoundException
import ch.srgssr.pillarbox.core.business.extension.getString
import java.io.IOException
/**
* Process error message from [PlaybackException]
*/
class SRGErrorMessageProvider(private val context: Context) : ErrorMessageProvider<PlaybackException> {
override fun getErrorMessage(throwable: PlaybackException): Pair<Int, String> {
return when (val cause = throwable.cause) {
is BlockReasonException -> {
Pair.create(0, context.getString(cause.blockReason))
}
is ResourceNotFoundException -> {
Pair.create(0, context.getString(R.string.noPlayableResourceFound))
}
is DataParsingException -> {
Pair.create(0, context.getString(R.string.invalidDataError))
}
is HttpResultException -> {
Pair.create(0, cause.message)
}
is DataSourceException -> {
Pair.create(cause.reason, cause.message)
}
is IOException -> {
Pair.create(0, context.getString(R.string.NoInternet))
}
else -> {
Pair.create(throwable.errorCode, context.getString(R.string.unknownError))
}
}
}
}