<commit_before>var Promise = require("bluebird");

module.exports = (response, body) => {
  var outResponse = {
    statusCode: response.statusCode,
    headers: response.headers,
    body: body
  };

  if (response.statusCode != 200) {
    var errorResponse = outResponse;
    if (response.headers['content-type'] === 'application/json;charset=UTF-8') {
      var responseBody = JSON.parse(body);
      errorResponse.errorCode = responseBody.errorCode;
      errorResponse.message = responseBody.message;
      errorResponse.refId = responseBody.refId;
    } else {
      errorResponse.message = body;
    }

    return new Promise.reject(errorResponse);
  } else if (response.headers['content-type'] === 'application/json;charset=UTF-8') {
    outResponse.content = JSON.parse(body);
    return outResponse;
  } else {
    outResponse.content = body;
    return outResponse;
  }
};
<commit_msg>Add support for error detail<commit_after>var Promise = require("bluebird");

module.exports = (response, body) => {
  var outResponse = {
    statusCode: response.statusCode,
    headers: response.headers,
    body: body
  };

  if (response.statusCode != 200) {
    var errorResponse = outResponse;
    if (response.headers['content-type'] === 'application/json;charset=UTF-8') {
      var responseBody = JSON.parse(body);
      errorResponse.errorCode = responseBody.errorCode;
      errorResponse.message = responseBody.message;
      errorResponse.refId = responseBody.refId;
      
      if (responseBody.detail !== undefined) {
        errorResponse.detail = responseBody.detail;
      }
    } else {
      errorResponse.message = body;
    }

    return new Promise.reject(errorResponse);
  } else if (response.headers['content-type'] === 'application/json;charset=UTF-8') {
    outResponse.content = JSON.parse(body);
    return outResponse;
  } else {
    outResponse.content = body;
    return outResponse;
  }
};

{'fraction_non_alphanumeric': 0.12701717855283706, 'fraction_numerical': 0.0052056220718375845, 'mean_word_length': 3.3881278538812785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6691433', 'n_tokens_mistral': 568, 'n_tokens_neox': 553, 'n_words': 111}