oidc: starting with new .json model files is not worth a log line

This commit is contained in:
Johannes Zellner
2024-04-29 09:19:37 +02:00
parent a756fa9e9b
commit 7eda1136ea

View File

@@ -148,14 +148,13 @@ function load(modelName) {
if (DATA_STORE[modelName]) return;
const filePath = path.join(paths.OIDC_STORE_DIR, `${modelName}.json`);
// debug(`load: model ${modelName} based on ${filePath}.`);
debug(`load: model ${modelName} based on ${filePath}.`);
let data = {};
try {
data = JSON.parse(fs.readFileSync(filePath), 'utf8');
} catch (e) {
if (e.code === 'ENOENT') debug(`load: failed to read ${filePath}, start with new one.`);
else debug(`load: failed to read ${filePath}, use in-memory. %o`, e);
if (e.code !== 'ENOENT') debug(`load: failed to read ${filePath}, use in-memory. %o`, e);
}
DATA_STORE[modelName] = data;
@@ -167,12 +166,11 @@ function save(modelName) {
if (!DATA_STORE[modelName]) return;
const filePath = path.join(paths.OIDC_STORE_DIR, `${modelName}.json`);
// debug(`save: model ${modelName} to ${filePath}.`);
try {
fs.writeFileSync(filePath, JSON.stringify(DATA_STORE[modelName], null, 2), 'utf8');
} catch (e) {
debug(`save: failed to write ${filePath}`, e);
debug(`save: model ${modelName} failed to write ${filePath}`, e);
}
}