Skip to content

Commit a5d3b96

Browse files
committed
Improve external handler error reporting
1 parent fc2a1df commit a5d3b96

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

app/src/main/java/com/orgzly/android/external/actionhandlers/ExternalAccessActionHandler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.content.Intent
55
import com.orgzly.android.App
66
import com.orgzly.android.data.DataRepository
7-
import com.orgzly.android.external.types.ExternalHandlerFailure
87
import com.orgzly.android.external.types.Response
98
import javax.inject.Inject
109

@@ -40,7 +39,7 @@ abstract class ExternalAccessActionHandler : ExternalIntentParser {
4039
fullNameActions[intent.action!!]
4140
?.let { it(intent, context) }
4241
?.let { Response(true, if (it is Unit) null else it) }
43-
} catch (e: ExternalHandlerFailure) {
42+
} catch (e: Exception) {
4443
Response(false, e.message)
4544
}
4645
}

app/src/main/java/com/orgzly/android/external/actionhandlers/ExternalIntentParser.kt

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.orgzly.android.external.actionhandlers
33
import android.content.Intent
44
import com.google.gson.JsonElement
55
import com.google.gson.JsonObject
6-
import com.google.gson.JsonParseException
76
import com.google.gson.JsonParser
87
import com.orgzly.android.data.DataRepository
98
import com.orgzly.android.db.entity.NoteView
@@ -22,31 +21,26 @@ interface ExternalIntentParser {
2221
val rawJson = getStringExtra("NOTE_PAYLOAD")
2322
val json = try {
2423
JsonParser.parseString(rawJson)
25-
.let { if (it.isJsonObject) it.asJsonObject else null }
26-
} catch (e: JsonParseException) {
27-
null
28-
}
29-
30-
return try {
31-
json!!
32-
NotePayload(
33-
(json.getString("title") ?: title)!!,
34-
json.getString("content"),
35-
json.getString("state"),
36-
json.getString("priority"),
37-
json.getString("scheduled"),
38-
json.getString("deadline"),
39-
json.getString("closed"),
40-
(json.getString("tags") ?: "")
41-
.split(" +".toRegex())
42-
.filter { it.isNotEmpty() },
43-
OrgProperties().apply {
44-
json["properties"]?.asMap?.forEach { (k, v) -> this[k] = v }
45-
}
46-
)
47-
} catch (e: NullPointerException) {
48-
throw ExternalHandlerFailure("invalid payload")
24+
.let { if (it.isJsonObject) it.asJsonObject else null }!!
25+
} catch (e: Exception) {
26+
throw ExternalHandlerFailure("failed to parse json: ${e.message}\n$rawJson")
4927
}
28+
return NotePayload(
29+
json.getString("title") ?: title
30+
?: throw ExternalHandlerFailure("no title supplied!\n$rawJson"),
31+
json.getString("content"),
32+
json.getString("state"),
33+
json.getString("priority"),
34+
json.getString("scheduled"),
35+
json.getString("deadline"),
36+
json.getString("closed"),
37+
(json.getString("tags") ?: "")
38+
.split(" +".toRegex())
39+
.filter { it.isNotEmpty() },
40+
OrgProperties().apply {
41+
json["properties"]?.asMap?.forEach { (k, v) -> this[k] = v }
42+
}
43+
)
5044
}
5145

5246
private fun getNoteByQuery(rawQuery: String?): NoteView {

0 commit comments

Comments
 (0)