Skip to content

Commit

Permalink
fix aemet fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed May 9, 2024
1 parent 7b58745 commit 8eefb11
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions services/aemet.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,30 @@ async function _getTimePrediction(name) {
'api_key': config.aemet.apiKey
}
}
const response = await fetch(endpoint, options)
const data = await response.json()
return await getAemetData(data.datos)

try {
const response = await fetch(endpoint, options)
const data = await response.json()
if (data?.datos) {
result = await getAemetData(data.datos)
}
} catch {
result = null
}

return result
}
async function getAemetData(url) {
const response = await fetch(url)
return await response.json()
let result = null
try {
const response = await fetch(url)
result = await response.json()

} catch {
result = null
}

return result
}

module.exports = {
Expand Down

0 comments on commit 8eefb11

Please sign in to comment.