Compare commits
2 commits
951511dcdf
...
98dc983435
Author | SHA1 | Date | |
---|---|---|---|
Peter Vacho | 98dc983435 | ||
Peter Vacho | 74832b840b |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,6 +9,7 @@
|
||||||
/.idea/assetWizardSettings.xml
|
/.idea/assetWizardSettings.xml
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/build
|
/build
|
||||||
|
/app/release
|
||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.cxx
|
.cxx
|
||||||
|
|
|
@ -25,6 +25,7 @@ android {
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
|
signingConfig = signingConfigs.getByName("debug")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|
|
@ -18,8 +18,28 @@ class GlobalExceptionHandler(
|
||||||
private val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
|
private val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
|
||||||
override fun uncaughtException(t: Thread, e: Throwable) {
|
override fun uncaughtException(t: Thread, e: Throwable) {
|
||||||
|
if (e is IllegalStateException) {
|
||||||
|
if (e.message?.startsWith("Unexpected response from ping: ") != true) throw e
|
||||||
|
|
||||||
|
Log.e("GlobalExceptionHandler", "Got IllegalStateException for unexpected ping response")
|
||||||
|
|
||||||
|
val msg = e.message!!.removePrefix("Unexpected response from ping: ")
|
||||||
|
if (msg.startsWith("exc - ")) {
|
||||||
|
val exc = msg.removePrefix("exc - ")
|
||||||
|
val exception = ExceptionSerializer.deserialize(exc)
|
||||||
|
Log.e("GlobalExceptionHandler", "Deserialized HTTP Exception")
|
||||||
|
Log.e("GlobalExceptionHandler", "Exception Type: ${exception.type}")
|
||||||
|
Log.e("GlobalExceptionHandler", "Message: ${exception.message}")
|
||||||
|
} else {
|
||||||
|
Log.e("GlobalExceptionHandler", "Exc:", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
navigateToApiUnreachableActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (e !is HttpException) {
|
if (e !is HttpException) {
|
||||||
Log.e("GlobalExceptionHandler", "Propgating unhandled exception", e)
|
Log.e("GlobalExceptionHandler", "Propagating unhandled exception", e)
|
||||||
defaultHandler?.uncaughtException(t, e)
|
defaultHandler?.uncaughtException(t, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -58,7 +78,23 @@ class GlobalExceptionHandler(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.e("GlobalExceptionHandler", "Propgating unhandled exception", e)
|
// ngrok
|
||||||
|
if (e.code() == 400) {
|
||||||
|
val errorBody = e.response()?.errorBody()?.string()
|
||||||
|
if (errorBody != null) {
|
||||||
|
val containsNgrokMeta = errorBody.contains("""<meta name="author" content="ngrok">""")
|
||||||
|
val containsNgrokMessage = errorBody.contains("Traffic was successfully tunneled")
|
||||||
|
|
||||||
|
if (containsNgrokMeta && containsNgrokMessage) {
|
||||||
|
Log.e("GlobalExceptionHandler", "Caught ngrok API Unreachable HTML Response")
|
||||||
|
navigateToApiUnreachableActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fall through
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.e("GlobalExceptionHandler", "Propagating unhandled exception", e)
|
||||||
defaultHandler?.uncaughtException(t, e)
|
defaultHandler?.uncaughtException(t, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,24 @@ class ApiUnreachableActivity : AppCompatActivity() {
|
||||||
Log.e("API_REACHABILITY", "Stacktrace: ${it.stacktrace.joinToString("\n")}")
|
Log.e("API_REACHABILITY", "Stacktrace: ${it.stacktrace.joinToString("\n")}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
if (e.message?.startsWith("Unexpected response from ping") != true) throw e
|
||||||
|
|
||||||
|
val msg = e.message!!.removePrefix("Unexpected response from ping: ")
|
||||||
|
if (msg.startsWith("exc - ")) {
|
||||||
|
exception = ExceptionSerializer.deserialize(msg.removePrefix("exc - "))
|
||||||
|
} else {
|
||||||
|
// This is a bit hacky, but we need a SerializedException to store here
|
||||||
|
val exc = ExceptionSerializer.serialize(e)
|
||||||
|
exception = ExceptionSerializer.deserialize(exc)
|
||||||
|
}
|
||||||
|
|
||||||
|
exception!!.let {
|
||||||
|
Log.e("API_REACHABILITY", "Exception: ${it.type}")
|
||||||
|
Log.e("API_REACHABILITY", "Message: ${it.message}")
|
||||||
|
Log.e("API_REACHABILITY", "Stacktrace: ${it.stacktrace.joinToString("\n")}")
|
||||||
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ import com.p_vacho.neat_calendar.api.services.EventsService
|
||||||
import com.p_vacho.neat_calendar.api.services.InvitationsService
|
import com.p_vacho.neat_calendar.api.services.InvitationsService
|
||||||
import com.p_vacho.neat_calendar.api.services.NotificationService
|
import com.p_vacho.neat_calendar.api.services.NotificationService
|
||||||
import com.p_vacho.neat_calendar.api.services.UsersService
|
import com.p_vacho.neat_calendar.api.services.UsersService
|
||||||
|
import com.p_vacho.neat_calendar.util.ExceptionSerializer
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
object RetrofitClient {
|
object RetrofitClient {
|
||||||
private const val DEFAULT_BASE_URL = "http://10.0.2.2:8000"
|
private const val DEFAULT_BASE_URL = "http://10.0.2.2:8000"
|
||||||
|
@ -115,8 +118,17 @@ object RetrofitClient {
|
||||||
* If the API isn't reachable, this will throw HttpException with code 503.
|
* If the API isn't reachable, this will throw HttpException with code 503.
|
||||||
*/
|
*/
|
||||||
suspend fun ping() {
|
suspend fun ping() {
|
||||||
// This will potentially raise 503 HttpException
|
val responseBody: ResponseBody
|
||||||
val responseBody = retrofitClient.create(GeneralService::class.java).ping()
|
try {
|
||||||
|
responseBody = retrofitClient.create(GeneralService::class.java).ping()
|
||||||
|
} catch (e: HttpException) {
|
||||||
|
// Unreachable
|
||||||
|
if (e.code() == 503) throw e
|
||||||
|
|
||||||
|
// Anything else:
|
||||||
|
val exc = ExceptionSerializer.serialize(e)
|
||||||
|
throw IllegalStateException("Unexpected response from ping: exc - $exc")
|
||||||
|
}
|
||||||
|
|
||||||
val responseText = responseBody.string()
|
val responseText = responseBody.string()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue