Improve error handling
- Use safeJson() and safePromiseAll() for centralized error handling - Enhance logging with structured debug flags
This commit is contained in:
parent
e472b99b44
commit
8f34aa5139
2 changed files with 39 additions and 19 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue