mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[GH-ISSUE #509] OAuthSwift creates errors reusing NSURLErrorDomain instead of its' own domain, OAuthSwiftError.Domain #336
Labels
No labels
bug
cocoapod
duplicate
enhancement
feature-request
help wanted
help wanted
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/OAuthSwift#336
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @nataliachodelski on GitHub (Jan 17, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/509
Description:
I encountered this issue when a token refresh with Microsoft Azure ActiveDirectory failed due to a password change by the user.
In this situation, the OAuthSwift library returned a 400 error code. The error was correctly parsed to add the OAuth error information into its'
userInfobut the error was returned with domainNSURLErrorDomainrather thanOAuthSwiftError.Example error as returned by line 183 of OAuthSwiftHTTPRequest.swift (line number references the current origin/master codebase file):
I believe this is an issue with the OAuthSwift because
NSURLErrorDomainis one of Apple's Foundation error domains for NSURLSession. The expected possible error codes are already defined listed inNSURLError.h, and do NOT include a code 400.My understanding is that returning an error using
NSURLErrorDomainis bad practice and possibly is a bug, as developers do not expect a non-apple library to reuse Apple's own error codes for custom errors.Best practice for error handling in Libraries/frameworks is for developers to create their own custom error domains and codes for their libraries and publish the error domains and codes with the documentation.
This approach has generally been followed in the OAuthSwift library in
OAuthSwiftError.swift, however the particular error I referenced is being created by OAuthSwift in a way that violates best practices. I believe the errors passed out of the OAuthSwift library SHOULD always have the domainOAuthSwiftError, since that is the whole point of defining an error domain and codes for this library to use in OAuthSwiftError.swift.--
Re: fixing this issue:
OAuth Provider? (Twitter, Github, ..):
Microsoft Azure Active Directory.
Using OAuth2.0 with the ExchangeActiveSync API
OAuth Version:
OS (Please fill the version) :
Installation method:
Library version:
Xcode version:
-[x] 10.1
9.3 (Swift 4.1)
9.0 (Swift 4.0)
9.0 (Swift 3.2)
8.x (Swift 3.x)
8.0 (Swift 2.3)
7.3.1
other: (Please fill in the version you are using.)
objective c
swift
@phimage commented on GitHub (Feb 21, 2019):
You are right the domain is wrong
We put http status code in the error, maybe a domain exist about that but not sure because I often import in my project a custom enum to list http errors code
Google use it own domain "Error Domain=com.google.HTTPStatus Code=400"
So "OAuthSwiftError.HTTPStatus" could be used
I we change somethings
a code to check