From ebdbc84ebbb5a3ec1e234d7bcf8fdffb6bef45e7 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Thu, 30 Apr 2015 08:43:31 +0200 Subject: [PATCH] Make it more resilient against API changes --- syncthing-bar/SyncthingRunner.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/syncthing-bar/SyncthingRunner.swift b/syncthing-bar/SyncthingRunner.swift index 04d401a..d09d6d9 100644 --- a/syncthing-bar/SyncthingRunner.swift +++ b/syncthing-bar/SyncthingRunner.swift @@ -123,6 +123,20 @@ class SyncthingRunner: NSObject { let request = createRequest("/rest/config") NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in + if (error != nil) { + println("Got error collecting repositories \(error)") + return; + } + let httpResponse = response as? NSHTTPURLResponse; + if httpResponse == nil { + println("Unexpected response"); + return; + } + + if httpResponse!.statusCode != 200 { + println("Got non 200 HTTP Response \(httpResponse!.statusCode)"); + return; + } if (error == nil) { var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary