       onError(error, response)
       return
     }
-      
+
     if let image = UIImage(data: data) {
       onSuccess(image)
     } else {

  static func createDataTask(url: String,
    onSuccess: (NSData, NSHTTPURLResponse)->(),
    onError: (NSError, NSHTTPURLResponse?)->()) -> NSURLSessionDataTask? {
      
    if let nsUrl = NSURL(string: url) {
      return createDataTask(nsUrl, onSuccess: onSuccess, onError: onError)
    }
    
    // Error converting string to NSURL
    onError(MoaHttpErrors.InvalidUrlString.new, nil)
    return nil
  }
  
  private static func createDataTask(nsUrl: NSURL,
    onSuccess: (NSData, NSHTTPURLResponse)->(),
    onError: (NSError, NSHTTPURLResponse?)->()) -> NSURLSessionDataTask? {
      
    return NSURLSession.sharedSession().dataTaskWithURL(nsUrl) { (data, response, error) in
      if let httpResponse = response as? NSHTTPURLResponse {
        if error == nil {

      onError(error, response)
    }
  }

  private static func validMimeType(mimeType: String) -> Bool {
    let validMimeTypes = ["image/jpeg", "image/pjpeg", "image/png"]
    return contains(validMimeTypes, mimeType)
