Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alsoIntercept400 #270

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Sources/DataLoader/OAuth2DataLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ open class OAuth2DataLoader: OAuth2Requestable {

/// If set to true, a 403 is treated as a 401. The default is false.
public var alsoIntercept403: Bool = false


/// If set to true, a 400 is treated as a 401. The default is false.
public var alsoIntercept400: Bool = false

/**
Designated initializer.
Expand Down Expand Up @@ -103,7 +105,7 @@ open class OAuth2DataLoader: OAuth2Requestable {
}

- parameter request: The request to execute
- parameter retry: Whether the request should be retried on 401 (and possibly 403)
- parameter retry: Whether the request should be retried on 401 (and possibly 400, 403)
- parameter callback: The callback to call when the request completes/fails
*/
open func perform(request: URLRequest, retry: Bool, callback: @escaping ((OAuth2Response) -> Void)) {
Expand All @@ -117,7 +119,10 @@ open class OAuth2DataLoader: OAuth2Requestable {
if self.alsoIntercept403, 403 == response.response.statusCode {
throw OAuth2Error.unauthorizedClient(nil)
}
let _ = try response.responseData()
if self.alsoIntercept400, 400 == response.response.statusCode {
throw OAuth2Error.unauthorizedClient(nil)
}
let _ = try response.responseData()
callback(response)
}

Expand Down