<commit_before>function shopPromises(shopifyAPI){

	var Promise = require("bluebird");

	function checkStatus(headers){
		// console.log('checkStatus\t\n'+JSON.stringify(headers, null, '  '));
		var status = headers.status;
		if(!status) return null;
		var code = status.slice(0,3);
		if(code.indexOf('4') === 0 || code.indexOf('5') === 0) return status;
		return null;
	}

	function stdHandler(resolve, reject, cb){
		return function(err, data, headers){
			if(cb) cb(headers);

			if(err){
				if(err instanceof Error) {
					reject(err);
					return;
				}
				console.log('error from request');
				var headerErr = checkStatus(headers);
				var errObj = headerErr ? new Error(headerErr) : new Error(err);
				errObj.shopify = err;
				reject(errObj);
				return;
			}

			var fail = checkStatus(headers);
			if(fail) {
				console.error(data);
				reject(new Error(fail));
				return;
			}

			resolve(data);
		};
	}
		

	function shopPUT(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).put( url, data, stdHandler(resolve,reject, cb));
		});
	}

	function shopPOST(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).post(url, data, stdHandler(resolve,reject, cb));
		});
	}

	function shopPATCH(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).patch(url, data, stdHandler(resolve,reject, cb));
		});
	}
	function shopGET(config, url, query, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).get(url, query, stdHandler(resolve,reject, cb));
		});
	}

	function shopDELETE(config, url){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config)['delete'](url, stdHandler(resolve,reject));
		});
	}

	return {
		get:shopGET,
		put:shopPUT,
		post:shopPOST,
		patch:shopPATCH,
		"delete" : shopDELETE
	};
}


module.exports = shopPromises;<commit_msg>stringify err status<commit_after>function shopPromises(shopifyAPI){

	var Promise = require("bluebird");

	function checkStatus(headers){
		// console.log('checkStatus\t\n'+JSON.stringify(headers, null, '  '));
		var status = headers.status;
		if(!status) return null;
		var code = status.slice(0,3);
		if(code.indexOf('4') === 0 || code.indexOf('5') === 0) return status;
		return null;
	}

	function stdHandler(resolve, reject, cb){
		return function(err, data, headers){
			if(cb) cb(headers);

			if(err){
				if(err instanceof Error) {
					reject(err);
					return;
				}
				console.log('error from request');
				var headerErr = checkStatus(headers);
				var errObj = headerErr ? new Error(JSON.stringify(headerErr)) : new Error(err);
				errObj.shopify = err;
				reject(errObj);
				return;
			}

			var fail = checkStatus(headers);
			if(fail) {
				console.error(data);
				reject(new Error(fail));
				return;
			}

			resolve(data);
		};
	}
		

	function shopPUT(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).put( url, data, stdHandler(resolve,reject, cb));
		});
	}

	function shopPOST(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).post(url, data, stdHandler(resolve,reject, cb));
		});
	}

	function shopPATCH(config, url, data, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).patch(url, data, stdHandler(resolve,reject, cb));
		});
	}
	function shopGET(config, url, query, cb){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config).get(url, query, stdHandler(resolve,reject, cb));
		});
	}

	function shopDELETE(config, url){
		return new Promise(function(resolve, reject){
			new shopifyAPI(config)['delete'](url, stdHandler(resolve,reject));
		});
	}

	return {
		get:shopGET,
		put:shopPUT,
		post:shopPOST,
		patch:shopPATCH,
		"delete" : shopDELETE
	};
}


module.exports = shopPromises;
{'fraction_non_alphanumeric': 0.15280266188891733, 'fraction_numerical': 0.0030714102892244687, 'mean_word_length': 4.2668463611859835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1635483', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1277, 'n_words': 289}