-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPM Prep - Use WordPressComRESTAPIInterfacing
for all sync GET and POST requests in the Swift code
#777
Conversation
WordPressComRESTAPIInterfacing
for all sync GET and POST requests in the Swift codeWordPressComRESTAPIInterfacing
for all sync GET and POST requests in the Swift code
if error.domain == WordPressComRestApiEndpointError.errorDomain, error.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue { | ||
let status = RewindStatus(state: .unavailable) | ||
success(status) | ||
let nsError = error as NSError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but IMO it's better to avoid casting to NSError here by using pattern matching.
if let apiError = error as? WordPressAPIError<WordPressRestApiEndpointError>,
case let .endpointError(endpointError) = apiError,
endpointError.code == .preconditionFailure {
// ....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right.
I guess you are suggesting to used the better typed error to ensure what we are handling is a legit API error. If the casting fails, we are in a edge case and should act differently.
Under that assumption, I opened #779 to address. Thanks!
if let response = response as? [String: Bool], | ||
let success = response[Constants.status] { | ||
completion(success, nil) | ||
} else { | ||
completion(false, JetpackInstallError(type: .installResponseError)) | ||
} | ||
}) { (error: NSError, _: HTTPURLResponse?) in | ||
}) { error, _ in | ||
let error = error as NSError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
See discussion at #777 (comment) with @crazytonyli
Description
Follows up on #766 applying the same pattern to all the
.GET
and.POST
usages.I changed each file/group of files with extensions in dedicated commits, in case one wants to review in chunks.
Testing Details
Not all code is covered by unit tests, unfortunately. But, these changes are really about swapping interfaces without changing the implementation. They should be safe—last famous words.
CHANGELOG.md
if necessary. — N.A.