         }
 
         session.dataTask(with: request, completionHandler: { (data, response, error) in
-            completion(error == nil ? responseBlock(response as? HTTPURLResponse ?? HTTPURLResponse(), data) : error)
+            if let httpResponse = response as? HTTPURLResponse {
+                completion(error == nil ? responseBlock(httpResponse, data) : error)
+            }
+            else {
+                completion(DataStoreClientError.badResponse)
+            }
         }).resume()
     }
 

        }

        session.downloadTask(with: request, completionHandler: { (url, response, error) in
            completion(error == nil ? responseBlock(response as? HTTPURLResponse ?? HTTPURLResponse(), url) : error)
        }).resume()
    }



        request.httpBody = requestContent
        session.dataTask(with: request, completionHandler: { (data, response, error) in
            if let httpResponse = response as? HTTPURLResponse {
                completion(error == nil ? responseBlock(httpResponse, data) : error)
            }
            else {
                completion(DataStoreClientError.badResponse)
            }
        }).resume()
    }

