Skip to content

Commit

Permalink
AccessTokenErrorCodes field of CNConfig added to increase flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Burdzicki committed Oct 30, 2023
1 parent b732ccf commit 2e9fe2e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ See? Easy peasy! Keep in mind that your token model has to conform to `AccessTok
- `defaultAccessTokenStrategy` - global strategy for storing access tokens. Available options are `.global` and `.custom(String)`.
- `keychainInstance` - keychain instance used by CombineNetworking to store/fetch access tokens from Apple's Keychain. If not provided, safe storage will be turned off (more info below)
- `accessTokenStorage` - an instance of an object implementing AccessTokenStorage protocol. It's used to manipulate access token. By default it uses built-in `CNStorage`. To use different storage, provide your own instance.
- `accessTokenErrorCodes` - array containing error codes that should trigger access token refresh action. Default: [401].

### Access Token Strategies

Expand Down
1 change: 1 addition & 0 deletions Sources/CombineNetworking/Config/CNConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CNConfig {
public static var defaultAccessTokenStrategy: AccessTokenStrategy = .global
public static var keychainInstance: Keychain?
public static var accessTokenStorage: AccessTokenStorage = CNStorage()
public static var accessTokenErrorCodes: [Int] = [401]

private init() {}

Expand Down
2 changes: 1 addition & 1 deletion Sources/CombineNetworking/Request/CNProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ open class CNProvider<T: Endpoint> {
)
}

if response.statusCode == 401 {
if CNConfig.accessTokenErrorCodes.contains(response.statusCode) {
var convertibleToken: AccessTokenConvertible? = try await endpoint.callbackTask?()

if convertibleToken == nil {
Expand Down

0 comments on commit 2e9fe2e

Please sign in to comment.