Properly handle 401 error when adding city and key is invalid
parent
3aa384b82d
commit
2a693ed161
|
@ -34,7 +34,7 @@ class CityController extends IntermediateController {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->mapper = $mapper;
|
$this->mapper = $mapper;
|
||||||
$this->settingsMapper = $settingsMapper;
|
$this->settingsMapper = $settingsMapper;
|
||||||
$this->apiKey = $settingsMapper->getApiKey($this->userId);
|
$this->apiKey = \OC::$server->getConfig()->getAppValue('weather', 'openweathermap_api_key', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,7 @@ class WeatherController extends IntermediateController {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->mapper = $mapper;
|
$this->mapper = $mapper;
|
||||||
$this->settingsMapper = $settingsMapper;
|
$this->settingsMapper = $settingsMapper;
|
||||||
$this->apiKey = $settingsMapper->getApiKey($this->userId);
|
$this->apiKey = \OC::$server->getConfig()->getAppValue('weather', 'openweathermap_api_key', '');
|
||||||
$this->metric = $settingsMapper->getMetric($this->userId);
|
$this->metric = $settingsMapper->getMetric($this->userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,6 @@ class SettingsMapper extends Mapper {
|
||||||
return $this->getSetting($userId, "home");
|
return $this->getSetting($userId, "home");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setApiKey ($userId, $apiKey) {
|
|
||||||
$this->setSetting("apikey", $userId, $apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getApiKey ($userId) {
|
|
||||||
return $this->getSetting($userId, "apikey");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMetric ($userId, $metric) {
|
public function setMetric ($userId, $metric) {
|
||||||
$this->setSetting("metric", $userId, $metric);
|
$this->setSetting("metric", $userId, $metric);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ app.controller('WeatherController', ['$scope', '$interval', '$timeout', '$compil
|
||||||
$scope.cityLoadNeedsAPIKey = false;
|
$scope.cityLoadNeedsAPIKey = false;
|
||||||
}
|
}
|
||||||
else if (r.status == 401) {
|
else if (r.status == 401) {
|
||||||
$scope.cityLoadError = "Your OpenWeatherMap API key is invalid. Please provide a working API Key.";
|
$scope.cityLoadError = "Your OpenWeatherMap API key is invalid. Contact your administrator to configure a valid API key in administration settings";
|
||||||
$scope.cityLoadNeedsAPIKey = true;
|
$scope.cityLoadNeedsAPIKey = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -232,7 +232,10 @@ app.controller('WeatherController', ['$scope', '$interval', '$timeout', '$compil
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (r) {
|
function (r) {
|
||||||
if (r.status == 404) {
|
if (r.status == 401) {
|
||||||
|
$scope.addCityError = "Your OpenWeatherMap API key is invalid. Contact your administrator to configure a valid API key in administration settings";
|
||||||
|
}
|
||||||
|
else if (r.status == 404) {
|
||||||
$scope.addCityError = "No city with this name found.";
|
$scope.addCityError = "No city with this name found.";
|
||||||
}
|
}
|
||||||
else if (r.status == 409) {
|
else if (r.status == 409) {
|
||||||
|
|
Loading…
Reference in New Issue