Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value <html> of type java.lang.String cannot be converted to JSONObject #163

Closed
niqo01 opened this issue Dec 11, 2023 · 4 comments
Closed

Comments

@niqo01
Copy link

niqo01 commented Dec 11, 2023

Expected Behavior

No error reported via the LoggerProvider

Current Behavior

The following error message is reported to the LoggerProvider error callback
Error when upload event: Value <html> of type java.lang.String cannot be converted to JSONObject

Steps to Reproduce

Unknown

Environment

  • Android SDK Kotlin Version: 1.12.2
  • Device: Samsung Galaxy A52s 5G, Xiaomi Poco X3 Pro, Samsung Galaxy M32
  • Device OS and Version: Android 13

Amplitude configuration

Configuration(
        apiKey = apiKey,
        context = context,
        loggerProvider = AmplitudeLoggerProvider(debug),
        trackingSessionEvents = true,
        useAppSetIdForDeviceId = true,
        migrateLegacyData = true
    )
@liuyang1520
Copy link
Collaborator

Hi @niqo01 ,

Thanks for reporting this! I haven't seen this error before, by reading the source code, it was logged here.

  • Could you provide a more detailed stacktrace if possible?
  • Is this happening on all users or a particular subset of users?

Thanks!

@niqo01
Copy link
Author

niqo01 commented Dec 12, 2023

Hi @liuyang1520

I am not able to provide a more detailed stacktrace. It's happening on a small subset of production devices in the wild. If a new version the Amplitude SDK could return the actual exception in the logger, that would be great.

Nicolas

@liuyang1520
Copy link
Collaborator

Hi @niqo01 ,

Got it. Is it possible for you to try this troubleshooting plugin? By reading the short error message above, it might be helpful to understand the event payload and see whether it is convertible to JSON.

Thanks!

@niqo01
Copy link
Author

niqo01 commented Feb 15, 2024

Here is a stacktrace:

Non-fatal Exception: com.couchsurfing.mobile.data.api.AmplitudeException: Stack trace: org.json.JSONException: Value <html> of type java.lang.String cannot be converted to JSONObject
	at org.json.JSON.typeMismatch(JSON.java:112)
	at org.json.JSONObject.<init>(JSONObject.java:169)
	at org.json.JSONObject.<init>(JSONObject.java:182)
	at com.amplitude.core.utilities.HttpClient$upload$1.close(SourceFile:116)
	at com.amplitude.core.platform.EventPipeline$upload$1.invokeSuspend(SourceFile:231)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
	at kotlinx.coroutines.DispatchedTask.run(SourceFile:113)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:923)

       at com.couchsurfing.mobile.data.api.AmplitudeException.<init>(AmplitudeException.java:3)
       at com.couchsurfing.mobile.data.api.AmplitudeLoggerProvider$getLogger$1.error(KotlinProvider.kt:50)
       at com.amplitude.core.utilities.LoggerExtensionsKt.logWithStackTrace(LoggerExtensions.kt:10)
       at com.amplitude.core.platform.EventPipeline$upload$1.invokeSuspend(EventPipeline.kt:147)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:923)

My guess is that the amplitude backend returns HTML response sometimes, probably for some 5XX or 4XX issues and when the SDK create a JSONObject for the response, it raises an exception. See the code here:
https://github.com/amplitude/Amplitude-Kotlin/blob/main/core/src/main/java/com/amplitude/core/utilities/HttpClient.kt#L42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants