github/api: avoid crashes with unparsable responses
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 28 Nov 2015 21:50:46 +0000 (16:50 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 28 Nov 2015 21:55:57 +0000 (16:55 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/github/api.nit

index 7e7400c..91cc006 100644 (file)
@@ -814,10 +814,16 @@ class Issue
                        for obj in array do
                                if not obj isa JsonObject then continue
                                var id = obj["id"].as(Int)
-                               res.add(api.load_issue_comment(repo, id).as(not null))
+                               var comment = api.load_issue_comment(repo, id)
+                               if comment == null then continue
+                               res.add(comment)
                        end
                        page += 1
-                       array = api.get("{key}/comments?page={page}").as(JsonArray)
+                       var json = api.get("{key}/comments?page={page}")
+                       if not json isa JsonArray then
+                               return res
+                       end
+                       array = json
                end
                return res
        end