fix: reading JSON string from service_usage_monthly

This was hilariously difficult to debug. This isn't the first time an
issue like this occurred; this happens because of a deviation between
mysql and sqlite, where a JSON-typed column in mysql will return as a
native object in queries, whereas a JSON-typed column in sqlite is a
string column and will therefore return as an un-parsed JSON string in
queries.
This commit is contained in:
KernelDeimos 2024-10-29 13:18:53 -04:00
parent 7ba16d1c21
commit b30de5bf78

View File

@ -63,8 +63,15 @@ module.exports = eggspress('/drivers/usage', {
let extra_parsed;
try {
extra_parsed = JSON.parse(row.extra);
extra_parsed = db.case({
mysql: () => row.extra,
otherwise: () => JSON.parse(row.extra),
})();
} catch ( e ) {
console.log(
'\x1B[31;1m error parsing monthly usage extra',
row.extra, e,
);
continue;
}