@@ -45,33 +45,37 @@ namespace appimage::update::updateinformation {
45
45
46
46
std::string builtUrl;
47
47
48
- // continue only if HTTP status is good
49
- if (response.status_code >= 200 && response.status_code < 300 ) {
50
- // in contrary to the original implementation, instead of converting wildcards into
51
- // all-matching regular expressions, we have the power of fnmatch() available, a real wildcard
52
- // implementation
53
- // unfortunately, this is still hoping for GitHub's JSON API to return a pretty printed
54
- // response which can be parsed like this
55
- std::stringstream responseText (response.text );
56
- std::string currentLine;
57
-
58
- // not ideal, but allows for returning a match for the entire line
59
- auto pattern = " *" + filename + " *" ;
60
-
61
- // iterate through all lines to find a possible download URL and compare it to the pattern
62
- while (std::getline (responseText, currentLine)) {
63
- if (currentLine.find (" browser_download_url" ) != std::string::npos) {
64
- downloadUrlLines++;
65
- if (fnmatch (pattern.c_str (), currentLine.c_str (), 0 ) == 0 ) {
66
- matchingUrls++;
67
- auto parts = util::split (currentLine, ' "' );
68
- builtUrl = std::string (parts.back ());
69
- break ;
70
- }
48
+ // continue only if request worked
49
+ if (response.error .code != cpr::ErrorCode::OK || response.status_code < 200 || response.status_code >= 300 ) {
50
+ std::ostringstream oss;
51
+ oss << " GitHub API request failed: HTTP status " << std::to_string (response.status_code )
52
+ << " , CURL error: " << response.error .message ;
53
+ throw UpdateInformationError (oss.str ());
54
+ }
55
+
56
+
57
+ // in contrary to the original implementation, instead of converting wildcards into
58
+ // all-matching regular expressions, we have the power of fnmatch() available, a real wildcard
59
+ // implementation
60
+ // unfortunately, this is still hoping for GitHub's JSON API to return a pretty printed
61
+ // response which can be parsed like this
62
+ std::stringstream responseText (response.text );
63
+ std::string currentLine;
64
+
65
+ // not ideal, but allows for returning a match for the entire line
66
+ auto pattern = " *" + filename + " *" ;
67
+
68
+ // iterate through all lines to find a possible download URL and compare it to the pattern
69
+ while (std::getline (responseText, currentLine)) {
70
+ if (currentLine.find (" browser_download_url" ) != std::string::npos) {
71
+ downloadUrlLines++;
72
+ if (fnmatch (pattern.c_str (), currentLine.c_str (), 0 ) == 0 ) {
73
+ matchingUrls++;
74
+ auto parts = util::split (currentLine, ' "' );
75
+ builtUrl = std::string (parts.back ());
76
+ break ;
71
77
}
72
78
}
73
- } else {
74
- throw UpdateInformationError (" GitHub API request failed!" );
75
79
}
76
80
77
81
if (downloadUrlLines <= 0 ) {
0 commit comments