The search is working better now. Also better and less debug logging.

This commit is contained in:
Scott Idem
2024-10-01 18:09:27 -04:00
parent fad58bf26f
commit 1c1845280b
5 changed files with 93 additions and 66 deletions

View File

@@ -101,7 +101,7 @@ export let get_object = async function get_object(
console.log('URL params:');
}
for (const prop in params) {
if (log_lvl) {
if (log_lvl > 1) {
console.log(`URL param: ${prop}: ${params[prop]}`);
}
if (params[prop] === null ) {
@@ -119,7 +119,7 @@ export let get_object = async function get_object(
let percent_completed = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
if (log_lvl) {
if (log_lvl > 1) {
console.log('GET Data Progress:', progressEvent.progress, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
}
@@ -206,6 +206,20 @@ export let get_object = async function get_object(
}
})
.catch(function (error) {
// Handle the common and expected 404 "error" first
if (error.response && error.response.status === 404) {
if (log_lvl) {
console.log('The response was a 404 not found "error". Returning null.');
}
if (log_lvl > 1) {
console.log(error.response);
}
if (log_lvl > 2) {
console.log(error);
}
return null; // Returning null since there were no results
}
if (log_lvl) {
console.log(`Base URL: ${api_cfg['base_url']} | Endpoint: ${endpoint}`);
console.log('Error Message:', error.message); // Is this needed here or below in the in the else portion???
@@ -230,18 +244,6 @@ export let get_object = async function get_object(
console.log(error.config);
}
if (error.response && error.response.status === 404) {
if (log_lvl) {
console.log('The response was a 404 not found "error". Returning null.');
}
if (log_lvl > 1) {
console.log(error.response);
}
if (log_lvl > 2) {
console.log(error);
}
return null; // Returning null since there were no results
}
if (error.code === 'ECONNABORTED') {
// Timeout Error (You can implement retry here where suitable)
console.log('Timeout Error: ', error.message);
@@ -265,7 +267,9 @@ export let get_object = async function get_object(
return response_data_promise;
} else if (response_data_promise === null) {
// Less common, but expected response if no results were returned.
console.log('Returning null. This is expected if no results were found.');
if (log_lvl) {
console.log('Returning null. This is expected if no results were found.');
}
return response_data_promise;
} else if (response_data_promise === false) {
// Not common, but expected response if the request to the API had an issue.

View File

@@ -81,6 +81,7 @@ export async function load_ae_obj_li__event(
inc_presenter_li = false,
inc_session_li = false,
order_by_li = {'start_datetime': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
params_json = null,
params = {},
try_cache = true,
log_lvl = 0
@@ -96,6 +97,7 @@ export async function load_ae_obj_li__event(
inc_presenter_li?: boolean,
inc_session_li?: boolean,
order_by_li?: key_val,
params_json?: null|key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
@@ -108,19 +110,31 @@ export async function load_ae_obj_li__event(
let limit: number = (params.qry__limit ?? 99); // 99
let offset: number = (params.qry__offset ?? 0); // 0
let params_json: key_val = {};
params_json['and_qry'] = {};
// There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01
if (!params_json) {
params_json = {};
}
if (qry_conference) {
if (!params_json['and_qry']) {
params_json['and_qry'] = {};
}
params_json['and_qry']['conference'] = qry_conference;
} else if (qry_conference === false) {
if (!params_json['and_qry']) {
params_json['and_qry'] = {};
}
console.log('qry_conference is false!');
params_json['and_qry']['conference'] = qry_conference;
}
if (qry_str) {
if (!params_json['ft_qry']) {
params_json['ft_qry'] = {};
}
params_json['ft_qry'] = {};
params_json['ft_qry']['default_qry_str'] = qry_str;
params_json['ft_qry']['location_address_json_ext'] = qry_str;
@@ -191,8 +205,8 @@ export async function qry_ae_obj_li__event(
for_obj_type = 'account',
for_obj_id,
qry_conference = true,
qry_virtual = null,
qry_physical = null,
qry_virtual = null,
qry_type = null,
qry_str = null,
inc_file_li = false,
@@ -209,8 +223,8 @@ export async function qry_ae_obj_li__event(
for_obj_type: string,
for_obj_id: string,
qry_conference?: null|boolean,
qry_virtual?: null|boolean,
qry_physical?: null|boolean,
qry_virtual?: null|boolean,
qry_type?: null|string,
qry_str?: null|string,
inc_file_li?: boolean,
@@ -231,29 +245,28 @@ export async function qry_ae_obj_li__event(
let limit: number = (params.qry__limit ?? 99); // 99
let offset: number = (params.qry__offset ?? 0); // 0
// Build the params_json object. This needs to be documented better! -2024-10-01
let params_json: key_val = {};
params_json['and_qry'] = {};
if (qry_conference) {
params_json['and_qry']['conference'] = qry_conference;
} else if (qry_conference === false) {
console.log('qry_conference is false!');
params_json['and_qry']['conference'] = qry_conference;
}
// This is handled in the actual load_ae_obj_li__event() function. For now...?
// if (qry_conference) {
// params_json['and_qry']['conference'] = qry_conference;
// } else if (qry_conference === false) {
// console.log('qry_conference is false!');
// params_json['and_qry']['conference'] = qry_conference;
// }
if (qry_virtual) {
params_json['and_qry']['virtual'] = qry_virtual;
} else if (qry_virtual === false) {
console.log('qry_virtual is false!');
params_json['and_qry']['virtual'] = qry_virtual;
}
if (qry_physical) {
params_json['and_qry']['physical'] = qry_physical;
} else if (qry_physical === false) {
console.log('qry_physical is false!');
params_json['and_qry']['physical'] = qry_physical;
if (qry_physical && qry_virtual) {
// Ignore both if both are set to true.
} else if (qry_physical || qry_virtual) {
if (qry_physical) {
params_json['and_qry']['physical'] = qry_physical;
}
if (qry_virtual) {
params_json['and_qry']['virtual'] = qry_virtual;
}
}
if (qry_type) {
@@ -283,6 +296,7 @@ export async function qry_ae_obj_li__event(
inc_presenter_li: inc_presenter_li,
inc_session_li: inc_session_li,
order_by_li: order_by_li,
params_json: params_json,
params: params,
try_cache: try_cache,
log_lvl: log_lvl

View File

@@ -73,6 +73,7 @@ import {
let export_obj = {
handle_load_ae_obj_id__event: events.load_ae_obj_id__event,
load_ae_obj_li__event: events.load_ae_obj_li__event,
qry_ae_obj_li__event: events.qry_ae_obj_li__event,
create_ae_obj__event: events.create_ae_obj__event,
update_ae_obj__event: events.update_ae_obj__event,
handle_db_save_ae_obj_li__event: events.db_save_ae_obj_li__event,