Skip to content

Commit

Permalink
Fix token expiration not refreshing the token
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasman committed Apr 5, 2024
1 parent 36acb0c commit a927ee1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/TeslaSwift/TeslaSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,17 @@ extension TeslaSwift {
logDebug(debugString, debuggingEnabled: debugEnabled)
if let wwwAuthenticate = httpResponse.allHeaderFields["Www-Authenticate"] as? String,
wwwAuthenticate.contains("invalid_token") {
token?.expiresIn = 0
throw TeslaError.tokenRevoked
} else if httpResponse.allHeaderFields["Www-Authenticate"] != nil, httpResponse.statusCode == 401 {
throw TeslaError.authenticationFailed
} else if let mapped = try? teslaJSONDecoder.decode(ErrorMessage.self, from: data) {
throw TeslaError.networkError(error: NSError(domain: "TeslaError", code: httpResponse.statusCode, userInfo: ["ErrorInfo": mapped]))
if mapped.description == "invalid bearer token" {
token?.expiresIn = 0
throw TeslaError.tokenRevoked
} else {
throw TeslaError.networkError(error: NSError(domain: "TeslaError", code: httpResponse.statusCode, userInfo: ["ErrorInfo": mapped]))
}
} else {
throw TeslaError.networkError(error: NSError(domain: "TeslaError", code: httpResponse.statusCode, userInfo: nil))
}
Expand Down

0 comments on commit a927ee1

Please sign in to comment.