From d3172ab3ae165b178834b05de90a4254e0214301 Mon Sep 17 00:00:00 2001 From: Bohdan Sukhomlinov Date: Thu, 15 Feb 2024 21:28:00 +0200 Subject: [PATCH] more informative errors --- mono_actual.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mono_actual.js b/mono_actual.js index 70b6d78..2cdec64 100644 --- a/mono_actual.js +++ b/mono_actual.js @@ -3,7 +3,7 @@ const actualApi = require('@actual-app/api'); const CACHE_DIR_PATH = '.cache/'; -const MONO_URL = 'https://api.monobank.ua/'; +const MONO_URL = 'https://api.monobank.ua'; const DAYS_TO_SYNC = parseInt(process.env.DAYS_TO_SYNC); const DEFAULT_DAYS_SYNC = DAYS_TO_SYNC < 7 ? DAYS_TO_SYNC : 7; const MONO_TOKEN = process.env.MONO_TOKEN; @@ -89,12 +89,13 @@ async function fetch_data() { async function fetchMonoData(card, startDateTimestamp, endDateTimestamp) { try { - const response = await fetch(MONO_URL + '/personal/statement/' + card + '/' + startDateTimestamp + '/' + endDateTimestamp, { + const mono_url = MONO_URL + '/personal/statement/' + card + '/' + startDateTimestamp + '/' + endDateTimestamp; + const response = await fetch(mono_url, { headers: { 'X-Token': MONO_TOKEN, }, }); if (!response.ok) { - throw new Error('API request failed'); + throw new Error(mono_url + ' failed: ' + ' ' + response.status + ' ' + response.statusText); } const data = await response.json();