mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 00:59:29 -07:00
Improve error handling
- Use safeJson() and safePromiseAll() for centralized error handling - Enhance logging with structured debug flags
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { json } from './fetch.mjs';
|
||||
import { safeJson } from './fetch.mjs';
|
||||
import { debugFlag } from './debug.mjs';
|
||||
|
||||
const getPoint = async (lat, lon) => {
|
||||
try {
|
||||
return await json(`https://api.weather.gov/points/${lat.toFixed(4)},${lon.toFixed(4)}`);
|
||||
} catch (error) {
|
||||
console.log(`Unable to get point ${lat}, ${lon}`);
|
||||
console.error(error);
|
||||
const point = await safeJson(`https://api.weather.gov/points/${lat.toFixed(4)},${lon.toFixed(4)}`);
|
||||
if (!point) {
|
||||
if (debugFlag('verbose-failures')) {
|
||||
console.warn(`Unable to get points for ${lat},${lon}`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return point;
|
||||
};
|
||||
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user