<commit_before>
function loadBackgroundImageFromUnsplash(keywords)
{
	/* Register your unsplash app here for a free, non-rate-limited developer-key:
	 * https://unsplash.com/documentation#registering-your-application
	 */
	var unsplashKey = '<KEY>';

	/* Reference: https://unsplash.com/documentation#search-photos */
	var unsplashUrl = 'https://api.unsplash.com/search/photos?client_id=' + unsplashKey + '&page=1&query=' + keywords;
	
	/* Trigger an ASYNC request to query list of images */
	get(unsplashUrl, populateBackgroundImageFromUnsplash);
}

/* Function triggerred upon expiry of "back-off from rate-limit" period */
function stopRateLimitingUnsplash()
{
	loadBackgroundImage.atUnsplashRateLimit = 0;
}

function populateBackgroundImageFromUnsplash()
{
	/* Obtain remaining queries as per rate-limit */
	var unsplashQueriesRemaining = this.getResponseHeader("x-ratelimit-remaining");
	
	if (unsplashQueriesRemaining == 0) {
		/* We have hit the unsplash hourly rate-limit.
		 * Set temporary backoff flasg for subsequent requests and fallback to flickr.
		 */
		loadBackgroundImage.atUnsplashRateLimit = 1;
		
		/* Backoff from unsplash for 5 to 15 minutes */
		var backoffDelay = (300000 + Math.floor(Math.random() * 300000));
		setTimeout(stopRateLimitingUnsplash, backoffDelay);
				
		loadBackgroundImageFromFlickr(keywords);
		return;
	}
	
	/* Hopefully received a valid JSON response of img search query */
	var response = this.responseText;
	
	/* Sometimes we may receive malformed JSON */
	try {
		var jsonObj = JSON.parse(response);
	} catch (e) {<commit_msg>Add unsplash server error handling<commit_after>
function loadBackgroundImageFromUnsplash(keywords)
{
	/* Register your unsplash app here for a free, non-rate-limited developer-key:
	 * https://unsplash.com/documentation#registering-your-application
	 */
	var unsplashKey = '<KEY>';

	/* Reference: https://unsplash.com/documentation#search-photos */
	var unsplashUrl = 'https://api.unsplash.com/search/photos?client_id=' + unsplashKey + '&page=1&query=' + keywords;
	
	/* Trigger an ASYNC request to query list of images */
	get(unsplashUrl, populateBackgroundImageFromUnsplash);
}

/* Function triggerred upon expiry of "back-off from rate-limit" period */
function stopRateLimitingUnsplash()
{
	loadBackgroundImage.atUnsplashRateLimit = 0;
}

function populateBackgroundImageFromUnsplash()
{
	/* Obtain remaining queries as per rate-limit */
	var unsplashQueriesRemaining = this.getResponseHeader("x-ratelimit-remaining");
	
	if (unsplashQueriesRemaining == 0) {
		/* We have hit the unsplash hourly rate-limit.
		 * Set temporary backoff flasg for subsequent requests and fallback to flickr.
		 */
		loadBackgroundImage.atUnsplashRateLimit = 1;
		
		/* Backoff from unsplash for 5 to 15 minutes */
		var backoffDelay = (300000 + Math.floor(Math.random() * 300000));
		setTimeout(stopRateLimitingUnsplash, backoffDelay);
				
		loadBackgroundImageFromFlickr(keywords);
		return;
	}

	/* Abort in case Unsplash returns an error */
	if (this.status != 200) {
		console.log('loadBackgroundImageFromUnsplash() returned error: ' + this.status);
		document.body.style.backgroundImage = 'none';
		document.getElementById('imgAttr').innerHTML = '';
		return;
	}
	
	/* Hopefully received a valid JSON response of img search query */
	var response = this.responseText;
	
	/* Sometimes we may receive malformed JSON */
	try {
		var jsonObj = JSON.parse(response);
	} catch (e) {
{'fraction_non_alphanumeric': 0.10850014505366985, 'fraction_numerical': 0.011894400928343487, 'mean_word_length': 4.570274636510501, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, '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': '2738806', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1039, 'n_words': 272}