old_contents: import {
  	parseUrl,
  	getHeaders,
  	isEmptyObject,
  	getCustomHeaders,
  	convertArrayToHeaders,
  } from '../utils';
  import CustomError from '../utils/CustomError';
  
  const testConnection = async (appname, rawUrl) => {
  	const defaultError = 'Unable to connect';
  	try {
  		const { url } = parseUrl(rawUrl);
  		const headers = getHeaders(rawUrl);
  		const customHeaders = getCustomHeaders(appname);
  
  		const res = await fetch(`${url}/${appname}`, {
  			'Content-Type': 'application/json',
  			headers: { ...headers, ...convertArrayToHeaders(customHeaders) },
  		}).then(response => response.json());
  
  		if (res.status >= 400) {
  			throw new CustomError(
  				JSON.stringify(res.error, null, 2),
  				`HTTP STATUS: ${res.status} - ${defaultError}`,
  			);
  		}
  
  		if (isEmptyObject(res)) {
  			throw new CustomError(
  				JSON.stringify(
  					{
  						error: `Unable to find ${appname}`,
  					},
  					null,
  					2,
  				),
  				`Error: Index not found`,
  			);
  		}
  		return res;
  	} catch (error) {
  		console.log(error);
  		const err = error;
  		if (err.message === 'Failed to fetch') {
  			err.message = defaultError;
  		}
  
  		throw new CustomError(
  			err.description && !isEmptyObject(JSON.parse(err.description))
  				? err.description
  				: `<b> Possible Errors </b>
  				<ul><li>Invalid connection string or index name </li>
  				<li> Please check is Elasticsearch cluster is up and running</li></ul>`,
  			err.message || defaultError,
  			err.stack,
  		);
  	}
  };
  
  export default testConnection;
  
new_contents: import {
  	parseUrl,
  	getHeaders,
  	isEmptyObject,
  	getCustomHeaders,
  	convertArrayToHeaders,
  } from '../utils';
  import CustomError from '../utils/CustomError';
  
  const testConnection = async (appname, rawUrl) => {
  	const defaultError = 'Unable to connect';
  	try {
  		const { url } = parseUrl(rawUrl);
  		const headers = getHeaders(rawUrl);
  		const customHeaders = getCustomHeaders(appname);
  
  		const res = await fetch(`${url}/${appname}`, {
  			'Content-Type': 'application/json',
  			headers: { ...headers, ...convertArrayToHeaders(customHeaders) },
  		}).then(response => response.json());
  
  		if (res.status >= 400) {
  			throw new CustomError(
  				JSON.stringify(res.error, null, 2),
  				`HTTP STATUS: ${res.status} - ${defaultError}`,
  			);
  		}
  
  		if (isEmptyObject(res)) {
  			throw new CustomError(
  				JSON.stringify(
  					{
  						error: `Unable to find ${appname}`,
  					},
  					null,
  					2,
  				),
  				`Error: Index not found`,
  			);
  		}
  		return res;
  	} catch (error) {
  		const err = error;
  		let description = `<b> Possible Errors </b>
  		<ul><li>Invalid connection string or index name </li>
  		<li> Please check is Elasticsearch cluster is up and running</li></ul>`;
  
  		if (err.message === 'Failed to fetch') {
  			err.message = defaultError;
  		}
  
  		if (err.message === 'NetworkError when attempting to fetch resource.') {
  			description = `You are trying to load http content over https.
  				You might have to enable mixed content of your browser
  				<a target="_blank" href="https://kb.iu.edu/d/bdny">https://kb.iu.edu/d/bdny</a>`;
  		}
  
  		throw new CustomError(
  			err.description && !isEmptyObject(JSON.parse(err.description))
  				? err.description
  				: description,
  			err.message || defaultError,
  			err.stack,
  		);
  	}
  };
  
  export default testConnection;
  
subject: Add custom message for mixed content