sumup / sumup-ios-sdk

Other
46 stars 24 forks source link

Informing about OAuth token expiration errors #63

Closed Ceroce closed 3 months ago

Ceroce commented 6 years ago

Hi,

Currently when an OAuth 2 access token has expired, the error has a generic “code 20”. We need to know that it is indeed a token expiration error, so we can request a new access token to the OAuth server.

For example, when calling SumUpSDK.login(withToken: accessToken, completion:), the error will be generic. Some code is needed to confirm it is a token expiration error:

private static func isAccessTokenExpiredError(_ error: Error) -> Bool {
    guard let nserror = error as NSError?,
        nserror.domain == "com.sumup.sdk",
        nserror.code == 20,
        let underlyingError = nserror.userInfo["NSUnderlyingError"] as? NSError,
        underlyingError.localizedDescription == "Access token invalid"
        else {
            return false
    }

    return true
}

I also dislike it because it is bound to the current implementation of the SDK. This error may have a different content in the future, and the code above would not work anymore.

Maybe the SDK could return a specific code to identify this special case. E.g.

SMPSumUpSDKErrorAccountTokenHasExpired   = 23

Thanks, Renaud

mollidor commented 6 years ago

Hi Renaud.

Thanks for pointing this out. I agree this should be more convenient and you shouldn't have to rely on some string matching magic.

We'll try to add a dedicated error code in an upcoming version of the SDK.

Regards, Lukas

mfhaberlach commented 4 years ago

@mollidor is there anything new here? We have to face the same Problem with the SDK

JullianSU commented 4 years ago

Hi mfhaberlach,

Thank you for taking the time contacting us, could you please share your merchant id at integration@sumup.com. We would like to verify something in your account.

Many thanks.