add error handling
This commit is contained in:
@@ -4,6 +4,7 @@ const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, openBudget,
|
|||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
async function getZestimate(URL) {
|
async function getZestimate(URL) {
|
||||||
|
try {
|
||||||
const response = await fetch(URL, {
|
const response = await fetch(URL, {
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
|
||||||
@@ -12,12 +13,22 @@ async function getZestimate(URL) {
|
|||||||
'Referer': 'https://www.google.com/',
|
'Referer': 'https://www.google.com/',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error fetching Zillow URL:');
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
try {
|
||||||
const dom = new jsdom.JSDOM(html);
|
const dom = new jsdom.JSDOM(html);
|
||||||
|
|
||||||
const zestimateText = dom.window.document.getElementById('home-details-home-values').getElementsByTagName('h3')[0].textContent;
|
const zestimateText = dom.window.document.getElementById('home-details-home-values').getElementsByTagName('h3')[0].textContent;
|
||||||
return parseInt(zestimateText.replace('$', '').replace(',', '')) * 100;
|
return parseInt(zestimateText.replace('$', '').replace(',', '')) * 100;
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error parsing Zillow page:');
|
||||||
|
console.log(error);
|
||||||
|
console.log(html);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user