Skip to content

Commit

Permalink
Parse to json only in the case of a successful response
Browse files Browse the repository at this point in the history
  • Loading branch information
Catalina Turlea committed Sep 17, 2018
1 parent d26939b commit 2ec31e0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/Flows/OAuth2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 2ec31e0

Please sign in to comment.