diff --git a/Sources/Flows/OAuth2.swift b/Sources/Flows/OAuth2.swift index 4c7ece5e..715af2e7 100644 --- a/Sources/Flows/OAuth2.swift +++ b/Sources/Flows/OAuth2.swift @@ -364,19 +364,20 @@ open class OAuth2: OAuth2Base { perform(request: post) { response in do { - let data = try response.responseData() - let json = try self.parseRefreshTokenResponseData(data) let statusCode = response.response.statusCode switch statusCode { case 400..<500: throw OAuth2Error.clientErrorWithStatus(statusCode) case 500...599: throw OAuth2Error.serverErrorWithStatus(statusCode) + case 200..<300: + let data = try response.responseData() + let json = try self.parseRefreshTokenResponseData(data) + self.logger?.debug("OAuth2", msg: "Did use refresh token for access token [\(nil != self.clientConfig.accessToken)]") + callback(json, nil) default: throw OAuth2Error.generic("Failed with status \(response.response.statusCode)") } - self.logger?.debug("OAuth2", msg: "Did use refresh token for access token [\(nil != self.clientConfig.accessToken)]") - callback(json, nil) } catch let error { self.logger?.debug("OAuth2", msg: "Error refreshing access token: \(error)")