Skip to content
Snippets Groups Projects
Unverified Commit 19da2aac authored by Philipp Woessner's avatar Philipp Woessner Committed by GitHub
Browse files

Feature/generic api exception (#425)


* added generic api exception message

* using already translated string

Co-authored-by: default avatarHee Tatt Ooi <hee.tatt.ooi@sap.com>
parent 0b6c2e82
No related branches found
No related tags found
No related merge requests found
......@@ -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),
}
......@@ -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)
......
......@@ -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,16 @@ 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_communication_with_api
)
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))
......
......@@ -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
}
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