Skip to content
Snippets Groups Projects
Unverified Commit cff09704 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Improve low storage error message (EXPOSUREAPP-2745) (#1190)

* Improve error message and add logic for future display of formatted error messages.

* Address PR review comments.
parent 49d4cdc5
No related branches found
No related tags found
No related merge requests found
package de.rki.coronawarnapp.storage package de.rki.coronawarnapp.storage
import android.content.Context
import android.text.format.Formatter
import de.rki.coronawarnapp.util.FormattedError
import java.io.IOException import java.io.IOException
class InsufficientStorageException( class InsufficientStorageException(
val result: DeviceStorage.CheckResult val result: DeviceStorage.CheckResult
) : IOException("Not enough free space (Want:${result.requiredBytes}; Have:${result.freeBytes}") ) : IOException(
"Not enough free space: ${result.requiredBytes}B are required and only ${result.freeBytes}B are available."
), FormattedError {
override fun getFormattedError(context: Context): String {
val formattedRequired = Formatter.formatShortFileSize(context, result.requiredBytes)
val formattedFree = Formatter.formatShortFileSize(context, result.freeBytes)
// TODO Replace with localized message when the exception is logged via new error tracking.
return "Not enough free space: $formattedRequired are required and only $formattedFree are available."
}
}
package de.rki.coronawarnapp.util
import android.content.Context
interface FormattedError {
fun getFormattedError(context: Context): String
}
fun Throwable.tryFormattedError(context: Context): String = when (this) {
is FormattedError -> this.getFormattedError(context)
else -> localizedMessage ?: this.toString()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment