Skip to content
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

Check http status code on feed downloads for a more precise error message #2049

Closed
EricShapiro opened this issue Dec 30, 2021 · 4 comments · Fixed by #2073
Closed

Check http status code on feed downloads for a more precise error message #2049

EricShapiro opened this issue Dec 30, 2021 · 4 comments · Fixed by #2073
Milestone

Comments

@EricShapiro
Copy link

EricShapiro commented Dec 30, 2021

Summary

Sparkle 2.0.0 is displaying "An error occurred while parsing the update feed" when the problem is actually a permission error from the web server. Checking the http statusCode would allow for a better error message.

Details:
Our feed is protected by CloudFront. If the user's access token expires, CloudFront returns a 503 error along with an HTML page explaining the issue. Sparkle's NSURLSessionDownloadTask delegate doesn't check the http status code on the download and attempts to parse the HTML error page from CloudFront. This results in the slightly erroneous but confusing error message above.

Possible Fix

I believe this can be fixed in SPUDownloader.m: didFinishDownloadingToURL by checking the statusCode and using a new error message if it indicates an error. A (Swift - sorry) example on checking the statusCode is shown below:

    func urlSession(_ session: URLSession, 
      downloadTask: URLSessionDownloadTask, 
      didFinishDownloadingTo location: URL) {

      if let response = downloadTask.response as? HTTPURLResponse {
        if response.statusCode < 200 || response.statusCode >= 400 {
          error = "Status code \(response.statusCode)"
          return
        }
      }
      // download was successful
    }

An improved message might be something as simple as "A network error occurred while downloading the update feed (503)."

SparkleUpdateError

Version

2.0.0

@zorgiepoo
Copy link
Member

We display a generic error (which is localizable and has translations) to the user and log out the underlying NSError from NSURLSession (from - (void)URLSession:(NSURLSession *)__unused session task:(NSURLSessionTask *)__unused task didCompleteWithError:(NSError *)error). To users the error message suggested here is not much more helpful. To developers I believe the underlying error is logged out in more detail. Likely 1.x would show this same error message too.

@EricShapiro
Copy link
Author

EricShapiro commented Dec 30, 2021

The error in this case is nil within didCompleteWithError. I guess that's just how URLSessionDownloadTask works - it's not http specific so doesn't check http error codes.

Certain generic connection errors, like server not found, do appear in that routine, but not http status codes.

@zorgiepoo
Copy link
Member

zorgiepoo commented Dec 30, 2021

Ah right, this error is happening later on when trying to parse the downloaded contents.. Then yeah it would be an improvement to check the http status code and maybe re-use the An error occurred while downloading the update. Please try again later. string, and maybe append the status code if it's not an issue grammar-wise with all languages.

Feel free to make a PR on this.

@zorgiepoo
Copy link
Member

Err that string I copied/pasted doesn't make sense :). We can have a new localizable string for this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants