Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Feature/generic api exception #425

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}