title: Handle No Internet Connection Error Before Try to Parse the Result in Alamofire
body: <p>How should I handle if there is an error occurs when there is no internet connection in Alamofire. I tried checking if data is nil or not but it does not work.</p>
  
  <p>Below is how I use Alamofire</p>
  
  <pre><code>Alamofire.request(.POST, REGISTER_URL, parameters: parameters, encoding: .JSON, headers: getAuthenticationHeader()).response { (request, response, data, errorType) -&gt; Void in
  
      let resultObject: APIResults = APIResults(JSONDecoder(data!));
      let responseCode: Int = Int(resultObject.code!)!;// THIS CRASHES WHEN THERE IS NO INTERNET CONNECTION
  
      if (responseCode == 200) {
          available = true;
      }
  
      finished = true;
  
  }
  </code></pre>