mirror of
https://github.com/daledavies/jump.git
synced 2026-01-10 01:12:08 +01:00
Issue #59: Show content on weather API error
This commit is contained in:
@@ -1 +1 @@
|
||||
v1.3.1 (1678896002)
|
||||
v1.3.1 (1679061647)
|
||||
File diff suppressed because one or more lines are too long
@@ -132,6 +132,10 @@ export default class Main {
|
||||
this.eventemitter.emit('show-content');
|
||||
});
|
||||
|
||||
this.eventemitter.on('weather-error', error => {
|
||||
this.eventemitter.emit('show-content');
|
||||
});
|
||||
|
||||
this.eventemitter.on('clock-updated', clockdata => {
|
||||
if (this.timeelm != null) {
|
||||
this.timeelm.innerHTML = clockdata.formatted_time;
|
||||
|
||||
@@ -34,28 +34,32 @@ export default class Weather {
|
||||
}
|
||||
// Get some data from the weather api...
|
||||
fetch(apiurl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
console.error('JUMP ERROR: There was an issue with the OWM API... ' + data.error);
|
||||
return;
|
||||
}
|
||||
if (data.cod === 401) {
|
||||
.then(response => {
|
||||
if (response.status === 401) {
|
||||
console.error('JUMP ERROR: The OWM API key is invalid, check config.php');
|
||||
this.eventemitter.emit('weather-error');
|
||||
return;
|
||||
}
|
||||
// Determine if we should use the day or night variant of our weather icon.
|
||||
var daynightvariant = 'night';
|
||||
if (data.dt > data.sys.sunrise && data.dt < data.sys.sunset) {
|
||||
daynightvariant = 'day'
|
||||
}
|
||||
this.eventemitter.emit('weather-loaded', {
|
||||
locationcode: data.id,
|
||||
locationname: data.name,
|
||||
temp: Math.ceil(data.main.temp) + '°' + (JUMP.metrictemp ? 'C' : 'F'),
|
||||
description: data.weather[0].main,
|
||||
iconclass: 'wi-owm-' + daynightvariant + '-' + data.weather[0].id,
|
||||
timezoneshift: data.timezone*1000,
|
||||
response.json().then(data => {
|
||||
console.log(data);
|
||||
if (data.error) {
|
||||
console.error('JUMP ERROR: There was an issue with the OWM API... ' + data.error);
|
||||
this.eventemitter.emit('weather-error');
|
||||
return;
|
||||
}
|
||||
// Determine if we should use the day or night variant of our weather icon.
|
||||
var daynightvariant = 'night';
|
||||
if (data.dt > data.sys.sunrise && data.dt < data.sys.sunset) {
|
||||
daynightvariant = 'day'
|
||||
}
|
||||
this.eventemitter.emit('weather-loaded', {
|
||||
locationcode: data.id,
|
||||
locationname: data.name,
|
||||
temp: Math.ceil(data.main.temp) + '°' + (JUMP.metrictemp ? 'C' : 'F'),
|
||||
description: data.weather[0].main,
|
||||
iconclass: 'wi-owm-' + daynightvariant + '-' + data.weather[0].id,
|
||||
timezoneshift: data.timezone*1000,
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class Weather extends AbstractAPI {
|
||||
curl_close($ch);
|
||||
// If we had an error then return the error message and exit, otherwise return the API response.
|
||||
if (isset($curlerror)) {
|
||||
http_response_code(400);
|
||||
http_response_code(curl_getinfo($ch)['http_code']);
|
||||
die(json_encode(['error' => $curlerror]));
|
||||
}
|
||||
return $response;
|
||||
|
||||
@@ -1 +1 @@
|
||||
<script defer src="{{{wwwurl}}}/assets/js/index.b57ed030906eab7ad01e.min.js"></script>
|
||||
<script defer src="{{{wwwurl}}}/assets/js/index.4769124eb98e9f4445fe.min.js"></script>
|
||||
Reference in New Issue
Block a user