diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index bf25cee6..a2de946f 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -258,8 +258,8 @@ class ArveData(BaseRequestHandler): if (client_id == '' or client_secret == '' or arve_api_key == ''): # If the credentials are not defined, we skip the ARVE API connection - return self.finish('ARVE API credentials not defined.') - + return self.send_error(401) + http_client = AsyncHTTPClient() URL = 'https://arveapi.auth.eu-central-1.amazoncognito.com/oauth2/token' diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 1ab36325..cfd23c64 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -312,7 +312,6 @@ function show_sensors_data(url) { url: `${$('#url_prefix').data().calculator_prefix}/api/arve/v1/${HOTEL_ID}/${FLOOR_ID}`, type: 'GET', success: function (result) { - if (result.length == 0) return; // If the ARVE credentials were not defined, we don't have a valid result. DATA_FROM_SENSORS = result; result.map(room => { if (room['Details']['Online'] == false) return; // If the sensor is offline, it should not be added to the list. @@ -332,9 +331,10 @@ function show_sensors_data(url) { })); } }, - error: function() { - alert('Authentication Error - Something went wrong during the authentication process.'); - }, + error: function(_, _, errorThrown) { + if (errorThrown != 'Unauthorized') alert(errorThrown); + else alert('Unauthorized - Something went wrong during the ARVE API authentication process.'); + } }); } };