|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import Foundation |
| 16 | + |
| 17 | +/// The live model sent a message that the SDK failed to parse. |
| 18 | +/// |
| 19 | +/// This may indicate that the SDK version needs updating, a model is too old for the current SDK |
| 20 | +/// version, or that the model is just |
| 21 | +/// not supported. |
| 22 | +/// |
| 23 | +/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this. |
| 24 | +public struct LiveSessionUnsupportedMessageError: Error, Sendable, CustomNSError { |
| 25 | + let underlyingError: Error |
| 26 | + |
| 27 | + init(underlyingError: Error) { |
| 28 | + self.underlyingError = underlyingError |
| 29 | + } |
| 30 | + |
| 31 | + public var errorUserInfo: [String: Any] { |
| 32 | + [ |
| 33 | + NSLocalizedDescriptionKey: "Failed to parse a live message from the model. Cause: \(underlyingError.localizedDescription)", |
| 34 | + NSUnderlyingErrorKey: underlyingError, |
| 35 | + ] |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +/// The live session was closed, because the network connection was lost. |
| 40 | +/// |
| 41 | +/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this. |
| 42 | +public struct LiveSessionLostConnectionError: Error, Sendable, CustomNSError { |
| 43 | + let underlyingError: Error |
| 44 | + |
| 45 | + init(underlyingError: Error) { |
| 46 | + self.underlyingError = underlyingError |
| 47 | + } |
| 48 | + |
| 49 | + public var errorUserInfo: [String: Any] { |
| 50 | + [ |
| 51 | + NSLocalizedDescriptionKey: "The live session lost connection to the server. Cause: \(underlyingError.localizedDescription)", |
| 52 | + NSUnderlyingErrorKey: underlyingError, |
| 53 | + ] |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/// The live session was closed, but not for a reason the SDK expected. |
| 58 | +/// |
| 59 | +/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this. |
| 60 | +public struct LiveSessionUnexpectedClosureError: Error, Sendable, CustomNSError { |
| 61 | + let underlyingError: WebSocketClosedError |
| 62 | + |
| 63 | + init(underlyingError: WebSocketClosedError) { |
| 64 | + self.underlyingError = underlyingError |
| 65 | + } |
| 66 | + |
| 67 | + public var errorUserInfo: [String: Any] { |
| 68 | + [ |
| 69 | + NSLocalizedDescriptionKey: "The live session was closed for some unexpected reason. Cause: \(underlyingError.localizedDescription)", |
| 70 | + NSUnderlyingErrorKey: underlyingError, |
| 71 | + ] |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +/// The live model refused our request to setup a live session. |
| 76 | +/// |
| 77 | +/// This can occur due to the model not supporting the requested response modalities, the project |
| 78 | +/// not having access to the model, |
| 79 | +/// the model being invalid, or some internal error. |
| 80 | +/// |
| 81 | +/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this. |
| 82 | +public struct LiveSessionSetupError: Error, Sendable, CustomNSError { |
| 83 | + let underlyingError: Error |
| 84 | + |
| 85 | + init(underlyingError: Error) { |
| 86 | + self.underlyingError = underlyingError |
| 87 | + } |
| 88 | + |
| 89 | + public var errorUserInfo: [String: Any] { |
| 90 | + [ |
| 91 | + NSLocalizedDescriptionKey: "The model did not accept the live session request. Reason: \(underlyingError.localizedDescription)", |
| 92 | + NSUnderlyingErrorKey: underlyingError, |
| 93 | + ] |
| 94 | + } |
| 95 | +} |
0 commit comments