|
|
|
@ -3,19 +3,15 @@ package org.koitharu.kotatsu.utils.ext
|
|
|
|
import android.content.ActivityNotFoundException
|
|
|
|
import android.content.ActivityNotFoundException
|
|
|
|
import android.content.res.Resources
|
|
|
|
import android.content.res.Resources
|
|
|
|
import okio.FileNotFoundException
|
|
|
|
import okio.FileNotFoundException
|
|
|
|
import org.acra.ACRA
|
|
|
|
|
|
|
|
import org.acra.ktx.sendWithAcra
|
|
|
|
import org.acra.ktx.sendWithAcra
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.*
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.WrongPasswordException
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
|
|
|
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.parsers.exception.ContentUnavailableException
|
|
|
|
import org.koitharu.kotatsu.parsers.exception.ParseException
|
|
|
|
import org.koitharu.kotatsu.parsers.exception.ParseException
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Manga
|
|
|
|
|
|
|
|
import java.net.SocketTimeoutException
|
|
|
|
import java.net.SocketTimeoutException
|
|
|
|
|
|
|
|
|
|
|
|
fun Throwable.getDisplayMessage(resources: Resources) = when (this) {
|
|
|
|
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
|
|
|
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
|
|
|
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
|
|
|
is CloudFlareProtectedException -> resources.getString(R.string.captcha_required)
|
|
|
|
is CloudFlareProtectedException -> resources.getString(R.string.captcha_required)
|
|
|
|
is ActivityNotFoundException,
|
|
|
|
is ActivityNotFoundException,
|
|
|
|
@ -23,22 +19,21 @@ fun Throwable.getDisplayMessage(resources: Resources) = when (this) {
|
|
|
|
is UnsupportedFileException -> resources.getString(R.string.text_file_not_supported)
|
|
|
|
is UnsupportedFileException -> resources.getString(R.string.text_file_not_supported)
|
|
|
|
is FileNotFoundException -> resources.getString(R.string.file_not_found)
|
|
|
|
is FileNotFoundException -> resources.getString(R.string.file_not_found)
|
|
|
|
is EmptyHistoryException -> resources.getString(R.string.history_is_empty)
|
|
|
|
is EmptyHistoryException -> resources.getString(R.string.history_is_empty)
|
|
|
|
|
|
|
|
is ContentUnavailableException -> message
|
|
|
|
|
|
|
|
is ParseException -> shortMessage
|
|
|
|
is SocketTimeoutException -> resources.getString(R.string.network_error)
|
|
|
|
is SocketTimeoutException -> resources.getString(R.string.network_error)
|
|
|
|
is WrongPasswordException -> resources.getString(R.string.wrong_password)
|
|
|
|
is WrongPasswordException -> resources.getString(R.string.wrong_password)
|
|
|
|
else -> localizedMessage ?: resources.getString(R.string.error_occurred)
|
|
|
|
else -> localizedMessage
|
|
|
|
}
|
|
|
|
} ?: resources.getString(R.string.error_occurred)
|
|
|
|
|
|
|
|
|
|
|
|
fun Throwable.isReportable(): Boolean {
|
|
|
|
fun Throwable.isReportable(): Boolean {
|
|
|
|
if (this !is Exception) {
|
|
|
|
if (this !is Exception) {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this is ParseException || this is IllegalArgumentException || this is IllegalStateException
|
|
|
|
return this is ParseException || this is IllegalArgumentException ||
|
|
|
|
|
|
|
|
this is IllegalStateException || this is RuntimeException
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun Throwable.report(message: String?) {
|
|
|
|
fun Throwable.report(message: String?) {
|
|
|
|
CaughtException(this, message).sendWithAcra()
|
|
|
|
CaughtException(this, message).sendWithAcra()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun ACRA.setCurrentManga(manga: Manga?) = errorReporter.putCustomData("manga", manga?.publicUrl.toString())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class CaughtException(cause: Throwable, override val message: String?) : RuntimeException(cause)
|
|
|
|
|