@@ -162,33 +162,47 @@ actor SignalClient: Loggable {
162162 }
163163
164164 return connectResponse
165- } catch {
165+ } catch let connectionError {
166166 // Skip validation if user cancelled
167- if error is CancellationError {
168- await cleanUp ( withError: error )
169- throw error
167+ if connectionError is CancellationError {
168+ await cleanUp ( withError: connectionError )
169+ throw connectionError
170170 }
171171
172172 // Skip validation if reconnect mode
173173 if reconnectMode != nil {
174- await cleanUp ( withError: error )
175- throw error
174+ await cleanUp ( withError: connectionError )
175+ throw LiveKitError ( . network , internalError : connectionError )
176176 }
177177
178- await cleanUp ( withError: error )
178+ await cleanUp ( withError: connectionError )
179179
180- // Validate...
180+ // Attempt to validate with server
181181 let validateUrl = try Utils . buildUrl ( url,
182182 connectOptions: connectOptions,
183183 participantSid: participantSid,
184184 adaptiveStream: adaptiveStream,
185185 validate: true )
186-
187186 log ( " Validating with url: \( validateUrl) ... " )
188- let validationResponse = try await HTTP . requestValidation ( from: validateUrl, token: token)
189- log ( " Validate response: \( validationResponse) " )
190- // re-throw with validation response
191- throw LiveKitError ( . network, message: " Validation response: \" \( validationResponse) \" " )
187+ do {
188+ try await HTTP . requestValidation ( from: validateUrl, token: token)
189+ // Re-throw original error since validation passed
190+ throw LiveKitError ( . network, internalError: connectionError)
191+ } catch let validationError as LiveKitError where validationError. type == . validation {
192+ // Re-throw validation error
193+ throw validationError
194+ } catch {
195+ let validationMessage = if let liveKitError = error as? LiveKitError {
196+ liveKitError. message ?? liveKitError. localizedDescription
197+ } else {
198+ error. localizedDescription
199+ }
200+
201+ // Preserve validation request failure details while keeping the original connection error.
202+ throw LiveKitError ( . network,
203+ message: " Validation request failed: \( validationMessage) " ,
204+ internalError: connectionError)
205+ }
192206 }
193207 }
194208
0 commit comments