@@ -136,20 +136,25 @@ public class Client {
136136 }
137137
138138 let httpResponse = response as! HTTPURLResponse
139- let responseBody = try JSONDecoder ( ) . decode ( SignInResponse . self, from: data)
140-
141- switch httpResponse. statusCode {
142- case 200 :
143- return Current . network. dataTask ( with: URLRequest . olympusSession) . asVoid ( )
144- case 401 :
145- throw Error . invalidUsernameOrPassword ( username: accountName)
146- case 409 :
147- return self . handleTwoStepOrFactor ( data: data, response: response, serviceKey: serviceKey)
148- case 412 where Client . authTypes. contains ( responseBody. authType ?? " " ) :
149- throw Error . appleIDAndPrivacyAcknowledgementRequired
150- default :
151- throw Error . unexpectedSignInResponse ( statusCode: httpResponse. statusCode,
152- message: responseBody. serviceErrors? . map { $0. description } . joined ( separator: " , " ) )
139+ do {
140+ let responseBody = try JSONDecoder ( ) . decode ( SignInResponse . self, from: data)
141+ switch httpResponse. statusCode {
142+ case 200 :
143+ return Current . network. dataTask ( with: URLRequest . olympusSession) . asVoid ( )
144+ case 401 :
145+ throw Error . invalidUsernameOrPassword ( username: accountName)
146+ case 409 :
147+ return self . handleTwoStepOrFactor ( data: data, response: response, serviceKey: serviceKey)
148+ case 412 where Client . authTypes. contains ( responseBody. authType ?? " " ) :
149+ throw Error . appleIDAndPrivacyAcknowledgementRequired
150+ default :
151+ throw Error . unexpectedSignInResponse ( statusCode: httpResponse. statusCode,
152+ message: responseBody. serviceErrors? . map { $0. description } . joined ( separator: " , " ) )
153+ }
154+ } catch DecodingError . dataCorrupted where httpResponse. statusCode == 503 {
155+ throw Error . serviceTemporarilyUnavailable
156+ } catch {
157+ throw error
153158 }
154159 }
155160 }
0 commit comments