Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsto committed Sep 5, 2022
1 parent 52ece28 commit c7c06ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Sources/xcodeinstall/API/AuthenticationMFA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ extension AppleAuthenticator {
method: .POST,
body: try JSONEncoder().encode(body),
headers: requestHeader,
validResponse: .range(200..<400))

try await self.saveSession(response: response, session: session)
validResponse: .range(200..<404))

if response.statusCode == 400 {
throw AuthenticationError.invalidPinCode
} else if response.statusCode == 403 {
throw AuthenticationError.unexpectedHTTPReturnCode(code: 403)
} else {
try await self.saveSession(response: response, session: session)
}

// should we save additional cookies ?
// return (try await getDESCookie(), session)
Expand Down
2 changes: 1 addition & 1 deletion Sources/xcodeinstall/API/NetworkAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NetworkAgent {
let (data, response) = try await httpClient.data(for: request)
guard let httpResponse = response as? HTTPURLResponse,
validResponse.isValid(response: httpResponse.statusCode) else {
logger.error("=== HTTP ERROR. Status code not in range \(validResponse) ===")
logger.error("=== HTTP ERROR. Status code \((response as? HTTPURLResponse)!.statusCode) not in range \(validResponse) ===")
logger.debug("URLResponse : \(response)")
throw URLError(.badServerResponse)
}
Expand Down

0 comments on commit c7c06ef

Please sign in to comment.