@@ -3,7 +3,6 @@ package com.orgzly.android.external.actionhandlers
33import android.content.Intent
44import com.google.gson.JsonElement
55import com.google.gson.JsonObject
6- import com.google.gson.JsonParseException
76import com.google.gson.JsonParser
87import com.orgzly.android.data.DataRepository
98import 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