Compare commits
No commits in common. "98dc983435790b8f52f5045f8fa22015221e0541" and "951511dcdfe7bb9d746e415d211caf754be75e4f" have entirely different histories.
98dc983435
...
951511dcdf
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,7 +9,6 @@
|
|||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/app/release
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
|
|
|
@ -25,7 +25,6 @@ android {
|
|||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
|
|
|
@ -18,28 +18,8 @@ class GlobalExceptionHandler(
|
|||
private val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||
|
||||
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) {
|
||||
Log.e("GlobalExceptionHandler", "Propagating unhandled exception", e)
|
||||
Log.e("GlobalExceptionHandler", "Propgating unhandled exception", e)
|
||||
defaultHandler?.uncaughtException(t, e)
|
||||
return
|
||||
}
|
||||
|
@ -78,23 +58,7 @@ class GlobalExceptionHandler(
|
|||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
Log.e("GlobalExceptionHandler", "Propgating unhandled exception", e)
|
||||
defaultHandler?.uncaughtException(t, e)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -144,24 +144,6 @@ class ApiUnreachableActivity : AppCompatActivity() {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@ 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.NotificationService
|
||||
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 {
|
||||
private const val DEFAULT_BASE_URL = "http://10.0.2.2:8000"
|
||||
|
@ -118,17 +115,8 @@ object RetrofitClient {
|
|||
* If the API isn't reachable, this will throw HttpException with code 503.
|
||||
*/
|
||||
suspend fun ping() {
|
||||
val responseBody: ResponseBody
|
||||
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")
|
||||
}
|
||||
// This will potentially raise 503 HttpException
|
||||
val responseBody = retrofitClient.create(GeneralService::class.java).ping()
|
||||
|
||||
val responseText = responseBody.string()
|
||||
|
||||
|
|
Loading…
Reference in a new issue