Enonic version: 6.8
OS: Windows
I was wondering if anyone had a good tip on why I seem unable to catch errors from the http client lib? I am using the following snippet to get some data from a backend service, but if the backend service is unavailable (no port open on the url) I want to be able to handle this in a better way than a big red error page.
I am using the following code:
function getData(url, token) {
token = token || "";
var siteConfig = portal.getSiteConfig();
log.info("Requesting " + siteConfig.backendUrl + url);
var res = {};
try {
var resp = httpClient.request({
url: siteConfig.backendUrl + url,
method: 'GET',
headers: {
'Authorization': basicAuth,
'x-auth-token': token
},
contentType: 'application/json',
connectTimeout: 1000,
readTimeout: 1000
});
res = JSON.parse(resp.body);
}
catch(e) {
log.error("Unable to get data from " + url + ": " + e.message);
}
return {};
}
At the moment I am getting this error even with the try/catch: