[GH-ISSUE #291] error.code is inaccessible due to 'fileprivate' protection level #173

Closed
opened 2026-03-03 16:46:22 +03:00 by kerem · 4 comments
Owner

Originally created by @dbmrq on GitHub (Oct 11, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/291

When a request failed, I used to be able to check the error code, like this:

failure: { error in
    if error.code == 401 {
        //...
    }
}

Now with Swift 3 I can't do that anymore, I get that error: "'code' is inaccessible due to 'fileprivate' protection level".

Originally created by @dbmrq on GitHub (Oct 11, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/291 When a request failed, I used to be able to check the error code, like this: ``` swift failure: { error in if error.code == 401 { //... } } ``` Now with Swift 3 I can't do that anymore, I get that error: "'code' is inaccessible due to 'fileprivate' protection level".
kerem 2026-03-03 16:46:22 +03:00
Author
Owner

@phimage commented on GitHub (Oct 11, 2016):

see OAuthSwiftError

it could be an .tokenExpired or .requestError for code 401 (with last code, not released yet you have attribute underlyingError)

you can do a if

failure: { error in
    if case .tokenExpired == error {
        //...
    }
}

or a switch

failure: { error in
    switch error {
        case .tokenExpired (let underlyingError):
        //...
       case .requestError (let underlyingError):
        //...
       default:
    }
}

then you can cast to NSError or there is in swift _code

<!-- gh-comment-id:252844474 --> @phimage commented on GitHub (Oct 11, 2016): see [OAuthSwiftError](https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuthSwiftError.swift) it could be an `.tokenExpired` or `.requestError` for code 401 (with last code, not released yet you have attribute `underlyingError`) you can do a if ``` swift failure: { error in if case .tokenExpired == error { //... } } ``` or a switch ``` swift failure: { error in switch error { case .tokenExpired (let underlyingError): //... case .requestError (let underlyingError): //... default: } } ``` then you can cast to `NSError` or there is in swift `_code`
Author
Owner

@dbmrq commented on GitHub (Oct 11, 2016):

Ah, awesome, thanks!

<!-- gh-comment-id:252846061 --> @dbmrq commented on GitHub (Oct 11, 2016): Ah, awesome, thanks!
Author
Owner

@dbmrq commented on GitHub (Nov 22, 2016):

@phimage So I was doing what you described in your last answer here, but now I updated to the latest version and I get "Enum case 'tokenExpired' not found in type 'Error'". Any ideas?

PS: You should consider adding a change log. It would be a huge help figuring out this sort of stuff.

Edit: Ah, I just had to specify OAuthSwiftError.tokenExpired. Never mind. :)

<!-- gh-comment-id:262169025 --> @dbmrq commented on GitHub (Nov 22, 2016): @phimage So I was doing what you described in your last answer here, but now I updated to the latest version and I get "Enum case 'tokenExpired' not found in type 'Error'". Any ideas? PS: You should consider adding a change log. It would be a huge help figuring out this sort of stuff. Edit: Ah, I just had to specify `OAuthSwiftError.tokenExpired`. Never mind. :)
Author
Owner

@phimage commented on GitHub (Nov 22, 2016):

please refer to release for change log
then swift 3 has been a big big change, you cannot write every modifications

<!-- gh-comment-id:262201798 --> @phimage commented on GitHub (Nov 22, 2016): please refer to [release](https://github.com/OAuthSwift/OAuthSwift/releases) for change log then swift 3 has been a big big change, you cannot write every modifications
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#173
No description provided.