<commit_before>//
//  NetworkResponseHandler.swift
//  TABResourceLoader
//
//  Created by <NAME> on 11/02/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct NetworkResponseHandler {

  static func resultFrom<Resource: NetworkResourceType & DataResourceType>(resource: Resource, data: Data?, URLResponse: Foundation.URLResponse?, error: Error?) -> Result<Resource.Model> {

    if let HTTPURLResponse = URLResponse as? HTTPURLResponse {
      switch HTTPURLResponse.statusCode {
      case 400..<600:
        return .failure(NetworkServiceError.statusCodeError(statusCode: HTTPURLResponse.statusCode))
      default: break
      }
    }

    if let error = error {
      return .failure(NetworkServiceError.networkingError(error: error))
    }

    guard let data = data else {
      return .failure(NetworkServiceError.noData)
    }

    do {
      let model = try resource.model(from: data)
      return .success(model)
    } catch {
      return .failure(NetworkServiceError.networkingError(error: error))
    }
  }
}<commit_msg>Code review feedback<commit_after>//
//  NetworkResponseHandler.swift
//  TABResourceLoader
//
//  Created by <NAME> on 11/02/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct NetworkResponseHandler {

  static func resultFrom<Resource: NetworkResourceType & DataResourceType>(resource: Resource, data: Data?, URLResponse: Foundation.URLResponse?, error: Error?) -> Result<Resource.Model> {

    if let HTTPURLResponse = URLResponse as? HTTPURLResponse {
      switch HTTPURLResponse.statusCode {
      case 400..<600:
        return .failure(NetworkServiceError.statusCodeError(statusCode: HTTPURLResponse.statusCode))
      default: break
      }
    }

    if let error = error {
      return .failure(NetworkServiceError.networkingError(error: error))
    }

    guard let data = data else {
      return .failure(NetworkServiceError.noData)
    }

    do {
      let model = try resource.model(from: data)
      return .success(model)
    } catch {
      return .failure(error)
    }
  }
}
{'fraction_non_alphanumeric': 0.10300429184549356, 'fraction_numerical': 0.017167381974248927, 'mean_word_length': 3.187624750499002, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6719529', 'n_tokens_mistral': 619, 'n_tokens_neox': 573, 'n_words': 147}