Skip to content

Commit 2fc8b45

Browse files
committed
Fix error view
1 parent d4d1edd commit 2fc8b45

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

firebaseai/LiveAudioExample/Views/LiveErrorDetailsView.swift

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
@testable import FirebaseAI
15+
import FirebaseAI
1616
import MarkdownUI
1717
import SwiftUI
1818

@@ -22,10 +22,8 @@ struct LiveErrorDetailsView: View {
2222
var body: some View {
2323
NavigationView {
2424
Form {
25-
if let title = error.title {
26-
Section("Error type") {
27-
Text(title)
28-
}
25+
Section("Error type") {
26+
Text("\(error.self)")
2927
}
3028

3129
Section("Details") {
@@ -50,36 +48,14 @@ private struct SubtitleFormRow: View {
5048
}
5149
}
5250

53-
private extension Error {
54-
var title: String? {
55-
switch self {
56-
case _ as LiveSessionSetupError:
57-
"Failed to set up live session"
58-
case _ as LiveSessionLostConnectionError:
59-
"Lost connection to the model"
60-
case _ as LiveSessionUnexpectedClosureError:
61-
"Session was closed"
62-
case _ as LiveSessionUnsupportedMessageError:
63-
"Unsupported model message"
64-
default:
65-
nil
66-
}
51+
struct ExampleLiveSessionError: Error, CustomNSError {
52+
public var errorUserInfo: [String: Any] {
53+
[
54+
NSLocalizedDescriptionKey: "The live session lost connection to the server."
55+
]
6756
}
6857
}
6958

7059
#Preview("Live error") {
71-
let cause = NSError(domain: "network.api", code: 1, userInfo: [
72-
NSLocalizedDescriptionKey: "Network timed out.",
73-
])
74-
let error = LiveSessionLostConnectionError(underlyingError: cause)
75-
76-
LiveErrorDetailsView(error: error)
77-
}
78-
79-
#Preview("Unexpected error") {
80-
let error = NSError(domain: "network.api", code: 1, userInfo: [
81-
NSLocalizedDescriptionKey: "Network timed out.",
82-
])
83-
84-
LiveErrorDetailsView(error: error)
60+
LiveErrorDetailsView(error: ExampleLiveSessionError())
8561
}

firebaseai/LiveAudioExample/Views/LiveErrorView.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
@testable import FirebaseAI
15+
import FirebaseAI
1616
import SwiftUI
1717

1818
struct LiveErrorView: View {
@@ -35,10 +35,5 @@ struct LiveErrorView: View {
3535
}
3636

3737
#Preview {
38-
let cause = NSError(domain: "network.api", code: 1, userInfo: [
39-
NSLocalizedDescriptionKey: "Network timed out.",
40-
])
41-
let error = LiveSessionLostConnectionError(underlyingError: cause)
42-
43-
LiveErrorView(error: error)
38+
LiveErrorView(error: ExampleLiveSessionError())
4439
}

0 commit comments

Comments
 (0)