Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmccall committed Jan 28, 2022
1 parent b8ed246 commit 7660d6d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
package expo.modules.devlauncher.helpers

import android.net.Uri
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Headers
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import java.io.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

/**
* An extension which converts the OkHttp requests to coroutines.
*/
suspend inline fun Request.await(okHttpClient: OkHttpClient): Response {
return suspendCancellableCoroutine { callback ->
okHttpClient.newCall(this).enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
callback.resume(response)
}

override fun onFailure(call: Call, e: IOException) {
if (callback.isCancelled) {
return
}
callback.resumeWithException(e)
}
})
}
}

fun fetch(url: Uri, method: String, headers: Headers): Request =
Request.Builder().method(method, null).url(url.toString()).headers(headers).build()

fun post(url: Uri, requestBody: RequestBody, vararg headers: Pair<String, String>): Request =
Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package expo.modules.devlauncher.launcher.errors

import android.app.Activity
import android.app.Application
import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.os.Process
Expand Down Expand Up @@ -110,13 +109,7 @@ class DevLauncherUncaughtExceptionHandler(
}

try {
val url = Uri
.parse(controller.appHost.reactInstanceManager.devSupportManager.sourceUrl)
.buildUpon()
.path("logs")
.clearQuery()
.build()

val url = getLogsUrl()
val remoteLogManager = DevLauncherRemoteLogManager(DevLauncherKoinContext.app.koin.get(), url)
.apply {
deferError("Your app just crashed. See the error below.")
Expand All @@ -127,4 +120,18 @@ class DevLauncherUncaughtExceptionHandler(
Log.e("DevLauncher", "Couldn't send an exception to bundler. $e", e)
}
}

private fun getLogsUrl(): Uri {
val logsUrlFromManifest = controller.manifest?.getRawJson()?.optString("logUrl")
if (logsUrlFromManifest != null) {
return Uri.parse(logsUrlFromManifest)
}

return Uri
.parse(controller.appHost.reactInstanceManager.devSupportManager.sourceUrl)
.buildUpon()
.path("logs")
.clearQuery()
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ internal interface DevLauncherRemoteLogBody {
val message: String
val stack: String?

fun toJson(): String
override fun toString(): String
}

internal class DevLauncherSimpleRemoteLogBody(override val message: String) : DevLauncherRemoteLogBody {
override val stack: String? = null

override fun toJson(): String = message
override fun toString(): String = message
}

internal class DevLauncherExceptionRemoteLogBody(exception: Throwable) : DevLauncherRemoteLogBody {
override val message: String = exception.toString()
override val stack: String = exception.stackTraceToRemoteLogString()

override fun toJson(): String = Gson().toJson(this)
override fun toString(): String = Gson().toJson(this)
}

@Suppress("UNUSED")
internal data class DevLauncherRemoteLog(
val logBody: DevLauncherRemoteLogBody,
@Expose val level: String = "error"
) {
@Expose
val includesStack = logBody.stack !== null

@Suppress("UNUSED")
@Expose
private val body = logBody.toJson()
private val body = logBody.toString()

fun toJson(): String {
return GsonBuilder()
Expand Down

0 comments on commit 7660d6d

Please sign in to comment.