Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 8b6f6a8

Browse files
committed
Remove redundant error handling from asURLEncodedData
See discussion at https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/pull/717/files#r1045479156
1 parent 8abbb29 commit 8b6f6a8

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

WordPressAuthenticator/OAuth/OAuthError.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ enum OAuthError: LocalizedError {
33
// ASWebAuthenticationSession
44
case inconsistentWebAuthenticationSessionCompletion
55

6-
// OAuth token request
7-
case failedToBuildURLQuery
8-
case failedToEncodeURLQuery(query: String)
9-
106
var errorDescription: String {
117
switch self {
128
case .inconsistentWebAuthenticationSessionCompletion:
139
return "ASWebAuthenticationSession authentication finished with neither a callback URL nor error"
14-
case .failedToBuildURLQuery:
15-
return "Failed to build URL query string"
16-
case .failedToEncodeURLQuery(let query):
17-
return "Failed to encode URL query string '\(query)'"
1810
}
1911
}
2012
}

WordPressAuthenticator/OAuth/OAuthTokenRequestBody.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@ struct OAuthTokenRequestBody: Encodable {
3333
var components = URLComponents()
3434
components.queryItems = items
3535

36-
guard let query = components.query else {
37-
throw OAuthError.failedToBuildURLQuery
38-
}
39-
40-
guard let data = query.data(using: .utf8) else {
41-
throw OAuthError.failedToEncodeURLQuery(query: query)
42-
}
43-
44-
return data
36+
// We can assume `query` to never be nil because we set `queryItems` in the line above.
37+
return Data(components.query!.utf8)
4538
}
4639
}

0 commit comments

Comments
 (0)