Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 fix "Failed to parse" for custom Text messages
Browse files Browse the repository at this point in the history
CAI server might send `content` as a JSON object or simply as a string.
The latter will be supported with this commit.
  • Loading branch information
MarcoEidinger committed Jul 29, 2021
1 parent 8cf517e commit 30bcf40
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/SAPCAI/Foundation/Model/UIModelData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ public struct UIModelData: Decodable {
}

self.header = try container.decodeIfPresent(UIModelDataHeader.self, forKey: .header)
self.content = try container.decodeIfPresent(UIModelDataContent.self, forKey: .content)

do {
self.content = try container.decodeIfPresent(UIModelDataContent.self, forKey: .content)
} catch DecodingError.typeMismatch {
if let contentAsString = try container.decodeIfPresent(String.self, forKey: .content) {
self.content = UIModelDataContent(text: contentAsString)
}
}

self.detailsAvailable = try container.decodeIfPresent(Bool.self, forKey: .detailsAvailable)
self.buttons = try container.decodeIfPresent([UIModelDataAction].self, forKey: .buttons)

Expand Down

0 comments on commit 30bcf40

Please sign in to comment.