-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from StepicOrg/release/1.56
Release 1.56
- Loading branch information
Showing
137 changed files
with
2,753 additions
and
3,564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ApiRequestRetrier.swift | ||
// Stepic | ||
// | ||
// Created by Ostrenkiy on 18.03.2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
import Foundation | ||
import Alamofire | ||
import PromiseKit | ||
|
||
class ApiRequestRetrier: RequestRetrier, RequestAdapter { | ||
|
||
func adapt(_ urlRequest: URLRequest) throws -> URLRequest { | ||
var urlRequest = urlRequest | ||
for (headerField, value) in AuthInfo.shared.initialHTTPHeaders { | ||
urlRequest.setValue(value, forHTTPHeaderField: headerField) | ||
} | ||
return urlRequest | ||
} | ||
|
||
func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) { | ||
if let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 && request.retryCount == 0 { | ||
checkToken().then { | ||
completion(true, 0.0) | ||
}.catch { | ||
_ in | ||
completion(false, 0.0) | ||
} | ||
} else { | ||
completion(false, 0.0) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.