<commit_before>import Foundation

public protocol JSONPostRouter: Router {
    func postJSON<T>(session: RequestKitURLSession, expectedResultType: T.Type, completion: (json: T?, error: ErrorType?) -> Void) -> URLSessionDataTaskProtocol?
}

public extension JSONPostRouter {
    public func postJSON<T>(session: RequestKitURLSession = NSURLSession.sharedSession(), expectedResultType: T.Type, completion: (json: T?, error: ErrorType?) -> Void) -> URLSessionDataTaskProtocol? {
        guard let request = request() else {
            return nil
        }

        let data: NSData
        do {
            data = try NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions())
        } catch {
            completion(json: nil, error: error)
            return nil
        }

        let task = session.uploadTaskWithRequest(request, fromData: data) { data, response, error in
            if let response = response as? NSHTTPURLResponse {
                if response.statusCode != 201 {
                    let error = NSError(domain: errorDomain, code: response.statusCode, userInfo: nil)
                    completion(json: nil, error: error)
                    return
                }
            }

            if let error = error {
                completion(json: nil, error: error)
            } else {
                if let data = data {
                    do {
                        let JSON = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? T
                        completion(json: JSON, error: nil)
                    } catch {
                        completion(json: nil, error: error)
                    }
                }
            }
        }
        task.resume()
        return task
    }
}
<commit_msg>Check if response was succesfull<commit_after>import Foundation

public protocol JSONPostRouter: Router {
    func postJSON<T>(session: RequestKitURLSession, expectedResultType: T.Type, completion: (json: T?, error: ErrorType?) -> Void) -> URLSessionDataTaskProtocol?
}

public extension JSONPostRouter {
    public func postJSON<T>(session: RequestKitURLSession = NSURLSession.sharedSession(), expectedResultType: T.Type, completion: (json: T?, error: ErrorType?) -> Void) -> URLSessionDataTaskProtocol? {
        guard let request = request() else {
            return nil
        }

        let data: NSData
        do {
            data = try NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions())
        } catch {
            completion(json: nil, error: error)
            return nil
        }

        let task = session.uploadTaskWithRequest(request, fromData: data) { data, response, error in
            if let response = response as? NSHTTPURLResponse {
                if !response.wasSuccessful {
                    let error = NSError(domain: errorDomain, code: response.statusCode, userInfo: nil)
                    completion(json: nil, error: error)
                    return
                }
            }

            if let error = error {
                completion(json: nil, error: error)
            } else {
                if let data = data {
                    do {
                        let JSON = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? T
                        completion(json: JSON, error: nil)
                    } catch {
                        completion(json: nil, error: error)
                    }
                }
            }
        }
        task.resume()
        return task
    }
}

{'fraction_non_alphanumeric': 0.08421345191773208, 'fraction_numerical': 0.0008337965536409116, 'mean_word_length': 1.7368821292775665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2338909', 'n_tokens_mistral': 900, 'n_tokens_neox': 866, 'n_words': 249}