                 if case (200..<300)? = (response as? HTTPURLResponse)?.statusCode {
                     completion(Result(value: data))
                 } else {
-                    let json = try! JSONSerialization.jsonObject(with: data, options: [])
-                    completion(Result(error: .apiError(FoursquareAPIError(json: json))))
+                    do {
+                        let json = try JSONSerialization.jsonObject(with: data, options: [])
+                        completion(Result(error: .apiError(FoursquareAPIError(json: json))))
+                    } catch {
+                        completion(Result(error: .responseParseError(error)))
+                    }
                 }
             default:
                 fatalError("invalid response combination \(data.debugDescription), \(response.debugDescription), \(error.debugDescription).")


public enum FoursquareClientError: Error {
    case connectionError(Error)
    case apiError(FoursquareAPIError)
}


                if case (200..<300)? = (response as? HTTPURLResponse)?.statusCode {
                    completion(Result(value: data))
                } else {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: [])
                        completion(Result(error: .apiError(FoursquareAPIError(json: json))))
                    } catch {
                        completion(Result(error: .responseParseError(error)))
                    }
                }
            default:
                fatalError("invalid response combination \(data.debugDescription), \(response.debugDescription), \(error.debugDescription).")
