Commit b462b4b2 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Loguea la falta de recursos externos y responde

Para las peticiones internas a recursos internos, ahora siempre se
responde al cliente. En caso de que no se haya definido la ruta a el
recurso, se loguea el error y se devuelve el contenido vacío que
corresponda a cada caso.
parent e55341b6
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -74,6 +74,12 @@ function onOauthTokenRequest(req, res) {

	res.set('Content-Type', 'application/json');

	if (!oauthUrl || !oauthUrl.length) {
		logger.error('Missing OAuth URL, set it using OAUTH_URL environment variable');
		res.send('{}');
		return;
	}

	const getTokenUrl = oauthUrl + '/token',
		reqLibrary = getTokenUrl.indexOf('https') === -1 ? http : https;

@@ -147,6 +153,12 @@ function onConfigRequest(req, res) {
			configLastUpdated = Date.now();
		};

		if (!configUrl || !configUrl.length) {
			logger.error('Missing config URL, set it using CONFIG_URL environment variable');
			res.send('{}');
			return;
		}

		const reqLibrary = configUrl.indexOf('https') === -1 ? http : https;

		const internalReq = reqLibrary.request(configUrl, onOwnRequestResponse.bind(this, {
@@ -178,6 +190,16 @@ function onSitemapRequest(_req, res) {
			sitemapLastUpdated = Date.now();
		};

		if (!sitemapUrl || !sitemapUrl.length) {
			logger.error('Missing sitemap URL, set it using SITEMAP_URL environment variable');

			const emptySitemap = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset ' +
				'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"/>'

			res.send(emptySitemap);
			return;
		}

		const reqLibrary = sitemapUrl.indexOf('https') === -1 ? http : https;

		const internalReq = reqLibrary.request(sitemapUrl, onOwnRequestResponse.bind(this, {