From 1eb1df9e253b01209df9942ee1e6d446f598e7b4 Mon Sep 17 00:00:00 2001 From: Philipp Woessner Date: Fri, 12 Jun 2020 15:37:33 +0200 Subject: [PATCH 1/2] added generic api exception message --- .../rki/coronawarnapp/exception/reporting/ErrorCodes.kt | 1 + .../exception/reporting/ErrorReportReceiver.kt | 8 ++++++++ .../exception/reporting/ExceptionReporter.kt | 9 +++++++++ .../exception/reporting/ReportingConstants.kt | 1 + Corona-Warn-App/src/main/res/values/strings.xml | 2 ++ 5 files changed, 21 insertions(+) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorCodes.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorCodes.kt index 5b89a01d3dd..de691a2a977 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorCodes.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorCodes.kt @@ -21,5 +21,6 @@ enum class ErrorCodes(val code: Int) { // NONTECHNICAL NO_NETWORK_CONNECTIVITY(1), NOT_ENOUGH_AVAILABLE_SPACE_ON_DISK(2), + API_EXCEPTION(3), EXTERNAL_NAVIGATION(10), } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorReportReceiver.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorReportReceiver.kt index d9e4be92bf3..ff37fe4dd14 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorReportReceiver.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ErrorReportReceiver.kt @@ -36,6 +36,14 @@ class ErrorReportReceiver(private val activity: Activity) : BroadcastReceiver() message = context.resources.getString(resId) } + if (intent.hasExtra(ReportingConstants.ERROR_REPORT_API_EXCEPTION_CODE)) { + val apiStatusCode = intent.getIntExtra( + ReportingConstants.ERROR_REPORT_API_EXCEPTION_CODE, + ErrorCodes.REPORTED_EXCEPTION_UNKNOWN_PROBLEM.code + ) + message += "($apiStatusCode)" + } + val stack = intent.getStringExtra(ReportingConstants.ERROR_REPORT_STACK_EXTRA) val title = context.resources.getString(R.string.errors_generic_headline) val confirm = context.resources.getString(R.string.errors_generic_button_positive) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt index 2031a593644..c2b3e617f34 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt @@ -2,7 +2,9 @@ package de.rki.coronawarnapp.exception.reporting import android.content.Intent import androidx.localbroadcastmanager.content.LocalBroadcastManager +import com.google.android.gms.common.api.ApiException import de.rki.coronawarnapp.CoronaWarnApplication +import de.rki.coronawarnapp.R import de.rki.coronawarnapp.exception.ExceptionCategory import java.io.PrintWriter import java.io.StringWriter @@ -26,6 +28,13 @@ fun Throwable.report( this.resId?.let { intent.putExtra(ReportingConstants.ERROR_REPORT_RES_ID, it) } } + // override the message with a generic one if it is an ApiException + if (this is ApiException) { + intent.putExtra(ReportingConstants.ERROR_REPORT_RES_ID, R.string.errors_api_exception) + intent.putExtra(ReportingConstants.ERROR_REPORT_CODE_EXTRA, ErrorCodes.API_EXCEPTION.code) + intent.putExtra(ReportingConstants.ERROR_REPORT_API_EXCEPTION_CODE, this.statusCode) + } + val sw = StringWriter() this.printStackTrace() this.printStackTrace(PrintWriter(sw)) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ReportingConstants.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ReportingConstants.kt index bf3bba61597..be711c01353 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ReportingConstants.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ReportingConstants.kt @@ -8,6 +8,7 @@ object ReportingConstants { const val ERROR_REPORT_MESSAGE_EXTRA = "message" const val ERROR_REPORT_STACK_EXTRA = "stack" const val ERROR_REPORT_CODE_EXTRA = "code" + const val ERROR_REPORT_API_EXCEPTION_CODE = "api-exception-code" const val ERROR_REPORT_RES_ID = "res-id" val ERROR_REPORT_UNKNOWN_ERROR = ErrorCodes.REPORTED_EXCEPTION_UNKNOWN_PROBLEM.code } diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml index 8ed0ea77191..5fe7aab297a 100644 --- a/Corona-Warn-App/src/main/res/values/strings.xml +++ b/Corona-Warn-App/src/main/res/values/strings.xml @@ -1001,6 +1001,8 @@ ###################################### --> Sie sind nicht mit dem Internet verbunden. + + Es ist ein Fehler bei der Begegnungs-Aufzeichnung aufgetreten. Sie haben nicht genug Speicherplatz. From 1e612ddede4e1b62e66025337a4533409fe67708 Mon Sep 17 00:00:00 2001 From: Philipp Woessner Date: Fri, 12 Jun 2020 16:13:12 +0200 Subject: [PATCH 2/2] using already translated string --- .../coronawarnapp/exception/reporting/ExceptionReporter.kt | 5 ++++- Corona-Warn-App/src/main/res/values/strings.xml | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt index c2b3e617f34..3ad303932cb 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt @@ -30,7 +30,10 @@ fun Throwable.report( // override the message with a generic one if it is an ApiException if (this is ApiException) { - intent.putExtra(ReportingConstants.ERROR_REPORT_RES_ID, R.string.errors_api_exception) + intent.putExtra( + ReportingConstants.ERROR_REPORT_RES_ID, + R.string.errors_communication_with_api + ) intent.putExtra(ReportingConstants.ERROR_REPORT_CODE_EXTRA, ErrorCodes.API_EXCEPTION.code) intent.putExtra(ReportingConstants.ERROR_REPORT_API_EXCEPTION_CODE, this.statusCode) } diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml index 5fe7aab297a..8ed0ea77191 100644 --- a/Corona-Warn-App/src/main/res/values/strings.xml +++ b/Corona-Warn-App/src/main/res/values/strings.xml @@ -1001,8 +1001,6 @@ ###################################### --> Sie sind nicht mit dem Internet verbunden. - - Es ist ein Fehler bei der Begegnungs-Aufzeichnung aufgetreten. Sie haben nicht genug Speicherplatz.