]> git.basschouten.com Git - openhab-addons.git/commitdiff
[openweathermap] Improved exception handling (#11949)
authorChristoph Weitkamp <github@christophweitkamp.de>
Mon, 3 Jan 2022 13:00:25 +0000 (14:00 +0100)
committerGitHub <noreply@github.com>
Mon, 3 Jan 2022 13:00:25 +0000 (14:00 +0100)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapCommunicationException.java [deleted file]
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapConfigurationException.java [deleted file]
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapConnection.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/AbstractOpenWeatherMapHandler.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAirPollutionHandler.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHistoryHandler.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapUVIndexHandler.java
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapWeatherAndForecastHandler.java
bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/i18n/openweathermap.properties

diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapCommunicationException.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapCommunicationException.java
deleted file mode 100644 (file)
index 0a3df36..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.openweathermap.internal.connection;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link OpenWeatherMapCommunicationException} is a communication exception for the connections to OpenWeatherMap
- * API.
- *
- * @author Christoph Weitkamp - Initial contribution
- */
-@NonNullByDefault
-public class OpenWeatherMapCommunicationException extends RuntimeException {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Constructs a new exception with null as its detail message.
-     */
-    public OpenWeatherMapCommunicationException() {
-        super();
-    }
-
-    /**
-     * Constructs a new exception with the specified detail message.
-     *
-     * @param message Detail message
-     */
-    public OpenWeatherMapCommunicationException(@Nullable String message) {
-        super(message);
-    }
-
-    /**
-     * Constructs a new exception with the specified cause.
-     *
-     * @param cause The cause
-     */
-    public OpenWeatherMapCommunicationException(@Nullable Throwable cause) {
-        super(cause);
-    }
-
-    /**
-     * Constructs a new exception with the specified detail message and cause.
-     *
-     * @param message Detail message
-     * @param cause The cause
-     */
-    public OpenWeatherMapCommunicationException(@Nullable String message, @Nullable Throwable cause) {
-        super(message, cause);
-    }
-}
diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapConfigurationException.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/connection/OpenWeatherMapConfigurationException.java
deleted file mode 100644 (file)
index 2921410..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.openweathermap.internal.connection;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * The {@link OpenWeatherMapConfigurationException} is a configuration exception for the connections to OpenWeatherMap
- * API.
- *
- * @author Christoph Weitkamp - Initial contribution
- */
-@NonNullByDefault
-public class OpenWeatherMapConfigurationException extends IllegalArgumentException {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Constructs a new exception with null as its detail message.
-     */
-    public OpenWeatherMapConfigurationException() {
-        super();
-    }
-
-    /**
-     * Constructs a new exception with the specified detail message.
-     *
-     * @param message Detail message
-     */
-    public OpenWeatherMapConfigurationException(@Nullable String message) {
-        super(message);
-    }
-
-    /**
-     * Constructs a new exception with the specified cause.
-     *
-     * @param cause The cause
-     */
-    public OpenWeatherMapConfigurationException(@Nullable Throwable cause) {
-        super(cause);
-    }
-
-    /**
-     * Constructs a new exception with the specified detail message and cause.
-     *
-     * @param message Detail message
-     * @param cause The cause
-     */
-    public OpenWeatherMapConfigurationException(@Nullable String message, @Nullable Throwable cause) {
-        super(message, cause);
-    }
-}
index f4310e60e3be5f2d05c9ff70077daf845519eeaa..4808744a7cdfa13f1094e25bafad6c7fd7774c96 100644 (file)
@@ -15,7 +15,6 @@ package org.openhab.binding.openweathermap.internal.connection;
 import static org.eclipse.jetty.http.HttpMethod.GET;
 import static org.eclipse.jetty.http.HttpStatus.*;
 
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.time.ZoneId;
@@ -46,6 +45,8 @@ import org.openhab.binding.openweathermap.internal.dto.onecallhist.OpenWeatherMa
 import org.openhab.binding.openweathermap.internal.handler.OpenWeatherMapAPIHandler;
 import org.openhab.core.cache.ByteArrayFileCache;
 import org.openhab.core.cache.ExpiringCacheMap;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.io.net.http.HttpUtil;
 import org.openhab.core.library.types.PointType;
 import org.openhab.core.library.types.RawType;
@@ -121,11 +122,11 @@ public class OpenWeatherMapConnection {
      * @param location location represented as {@link PointType}
      * @return the current weather data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonWeatherData getWeatherData(@Nullable PointType location)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         return gson.fromJson(
                 getResponseFromCache(
                         buildURL(WEATHER_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
@@ -139,14 +140,14 @@ public class OpenWeatherMapConnection {
      * @param count number of hours
      * @return the hourly forecast data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonHourlyForecastData getHourlyForecastData(
             @Nullable PointType location, int count)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         if (count <= 0) {
-            throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-not-supported-number-of-hours");
+            throw new ConfigurationException("@text/offline.conf-error-not-supported-number-of-hours");
         }
 
         Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
@@ -163,14 +164,13 @@ public class OpenWeatherMapConnection {
      * @param count number of days
      * @return the daily forecast data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonDailyForecastData getDailyForecastData(@Nullable PointType location,
-            int count)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            int count) throws JsonSyntaxException, CommunicationException, ConfigurationException {
         if (count <= 0) {
-            throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-not-supported-number-of-days");
+            throw new ConfigurationException("@text/offline.conf-error-not-supported-number-of-days");
         }
 
         Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
@@ -186,11 +186,11 @@ public class OpenWeatherMapConnection {
      * @param location location represented as {@link PointType}
      * @return the UV Index data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonUVIndexData getUVIndexData(@Nullable PointType location)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         return gson.fromJson(
                 getResponseFromCache(
                         buildURL(UVINDEX_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
@@ -203,15 +203,14 @@ public class OpenWeatherMapConnection {
      * @param location location represented as {@link PointType}
      * @return the UV Index forecast data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable List<OpenWeatherMapJsonUVIndexData> getUVIndexForecastData(
             @Nullable PointType location, int count)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         if (count <= 0) {
-            throw new OpenWeatherMapConfigurationException(
-                    "@text/offline.conf-error-not-supported-uvindex-number-of-days");
+            throw new ConfigurationException("@text/offline.conf-error-not-supported-uvindex-number-of-days");
         }
 
         Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
@@ -227,11 +226,11 @@ public class OpenWeatherMapConnection {
      * @param location location represented as {@link PointType}
      * @return the Air Pollution data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonAirPollutionData getAirPollutionData(@Nullable PointType location)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         return gson.fromJson(
                 getResponseFromCache(
                         buildURL(AIR_POLLUTION_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
@@ -245,12 +244,11 @@ public class OpenWeatherMapConnection {
      * @param location location represented as {@link PointType}
      * @return the Air Pollution forecast data
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapJsonAirPollutionData getAirPollutionForecastData(
-            @Nullable PointType location)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            @Nullable PointType location) throws JsonSyntaxException, CommunicationException, ConfigurationException {
         return gson.fromJson(
                 getResponseFromCache(buildURL(AIR_POLLUTION_FORECAST_URL,
                         getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
@@ -303,12 +301,12 @@ public class OpenWeatherMapConnection {
      * @param excludeDaily if true, will not fetch hourly forecast data from the server
      * @return
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapOneCallAPIData getOneCallAPIData(@Nullable PointType location,
             boolean excludeMinutely, boolean excludeHourly, boolean excludeDaily, boolean excludeAlerts)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws JsonSyntaxException, CommunicationException, ConfigurationException {
         Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
         List<String> exclude = new ArrayList<>();
         if (excludeMinutely) {
@@ -339,12 +337,11 @@ public class OpenWeatherMapConnection {
      * @param days number of days in the past, relative to the current time.
      * @return
      * @throws JsonSyntaxException
-     * @throws OpenWeatherMapCommunicationException
-     * @throws OpenWeatherMapConfigurationException
+     * @throws CommunicationException
+     * @throws ConfigurationException
      */
     public synchronized @Nullable OpenWeatherMapOneCallHistAPIData getOneCallHistAPIData(@Nullable PointType location,
-            int days)
-            throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            int days) throws JsonSyntaxException, CommunicationException, ConfigurationException {
         Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
         // the API requests the history as timestamp in Unix time format.
         params.put(PARAM_HISTORY_DATE,
@@ -355,14 +352,14 @@ public class OpenWeatherMapConnection {
 
     private Map<String, String> getRequestParams(OpenWeatherMapAPIConfiguration config, @Nullable PointType location) {
         if (location == null) {
-            throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-missing-location");
+            throw new ConfigurationException("@text/offline.conf-error-missing-location");
         }
 
         Map<String, String> params = new HashMap<>();
         // API key (see https://openweathermap.org/appid)
         String apikey = config.apikey;
         if (apikey == null || (apikey = apikey.trim()).isEmpty()) {
-            throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-missing-apikey");
+            throw new ConfigurationException("@text/offline.conf-error-missing-apikey");
         }
         params.put(PARAM_APPID, apikey);
 
@@ -387,15 +384,7 @@ public class OpenWeatherMapConnection {
     }
 
     private String encodeParam(@Nullable String value) {
-        if (value == null) {
-            return "";
-        }
-        try {
-            return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
-        } catch (UnsupportedEncodingException e) {
-            logger.debug("UnsupportedEncodingException occurred during execution: {}", e.getLocalizedMessage(), e);
-            return "";
-        }
+        return value == null ? "" : URLEncoder.encode(value, StandardCharsets.UTF_8);
     }
 
     private @Nullable String getResponseFromCache(String url) {
@@ -421,26 +410,29 @@ public class OpenWeatherMapConnection {
                 case NOT_FOUND_404:
                     errorMessage = getErrorMessage(content);
                     logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
-                    throw new OpenWeatherMapConfigurationException(errorMessage);
+                    throw new ConfigurationException(errorMessage);
                 case TOO_MANY_REQUESTS_429:
                     // TODO disable refresh job temporarily (see https://openweathermap.org/appid#Accesslimitation)
                 default:
                     errorMessage = getErrorMessage(content);
                     logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
-                    throw new OpenWeatherMapCommunicationException(errorMessage);
+                    throw new CommunicationException(errorMessage);
             }
         } catch (ExecutionException e) {
-            String errorMessage = e.getLocalizedMessage();
-            logger.trace("Exception occurred during execution: {}", errorMessage, e);
+            String errorMessage = e.getMessage();
+            logger.debug("ExecutionException occurred during execution: {}", errorMessage, e);
             if (e.getCause() instanceof HttpResponseException) {
                 logger.debug("OpenWeatherMap server responded with status code {}: Invalid API key.", UNAUTHORIZED_401);
-                throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-invalid-apikey", e.getCause());
+                throw new ConfigurationException("@text/offline.conf-error-invalid-apikey", e.getCause());
             } else {
-                throw new OpenWeatherMapCommunicationException(errorMessage, e.getCause());
+                throw new CommunicationException(
+                        errorMessage == null ? "@text/offline.communication-error" : errorMessage, e.getCause());
             }
         } catch (InterruptedException | TimeoutException e) {
-            logger.debug("Exception occurred during execution: {}", e.getLocalizedMessage(), e);
-            throw new OpenWeatherMapCommunicationException(e.getLocalizedMessage(), e.getCause());
+            String errorMessage = e.getMessage();
+            logger.debug("InterruptedException or TimeoutException occurred during execution: {}", errorMessage, e);
+            throw new CommunicationException(errorMessage == null ? "@text/offline.communication-error" : errorMessage,
+                    e.getCause());
         }
     }
 
index 6f3e00b938715d5dea1e0843379fa1b4ae9475d8..ab5d26da85b802d2e26a0eacd3cffc290fa4fd56 100644 (file)
@@ -25,9 +25,9 @@ import javax.measure.Unit;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapLocationConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
@@ -137,9 +137,9 @@ public abstract class AbstractOpenWeatherMapHandler extends BaseThingHandler {
                 updateChannels();
                 updateStatus(ThingStatus.ONLINE);
             }
-        } catch (OpenWeatherMapCommunicationException e) {
+        } catch (CommunicationException e) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getLocalizedMessage());
-        } catch (OpenWeatherMapConfigurationException e) {
+        } catch (ConfigurationException e) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getLocalizedMessage());
         }
     }
@@ -149,11 +149,11 @@ public abstract class AbstractOpenWeatherMapHandler extends BaseThingHandler {
      *
      * @param connection {@link OpenWeatherMapConnection} instance
      * @return true, if the request for the OpenWeatherMap data was successful
-     * @throws OpenWeatherMapCommunicationException if there is a problem retrieving the data
-     * @throws OpenWeatherMapConfigurationException if there is a configuration error
+     * @throws CommunicationException if there is a problem retrieving the data
+     * @throws ConfigurationException if there is a configuration error
      */
     protected abstract boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException;
+            throws CommunicationException, ConfigurationException;
 
     /**
      * Updates all channels of this handler from the latest OpenWeatherMap data retrieved.
index b937c3ac842de17ea072e41f22139821d6980a4e..472280b9f6440657dba29640d1be33463ca9baa7 100644 (file)
@@ -22,10 +22,10 @@ import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapAirPollutionConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
 import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonAirPollutionData;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.unit.Units;
@@ -111,7 +111,7 @@ public class OpenWeatherMapAirPollutionHandler extends AbstractOpenWeatherMapHan
 
     @Override
     protected boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws CommunicationException, ConfigurationException {
         logger.debug("Update air pollution data of thing '{}'.", getThing().getUID());
         try {
             airPollutionData = connection.getAirPollutionData(location);
@@ -120,7 +120,7 @@ public class OpenWeatherMapAirPollutionHandler extends AbstractOpenWeatherMapHan
             }
             return true;
         } catch (JsonSyntaxException e) {
-            logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
+            logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
             return false;
         }
     }
index 60a4082e3b039fe4203afea45ed926b10edfdf26..763842d9e4e532371981e13a0a88990526c1a458 100644 (file)
@@ -25,8 +25,6 @@ import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapOneCallConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
 import org.openhab.binding.openweathermap.internal.dto.onecall.Alert;
 import org.openhab.binding.openweathermap.internal.dto.onecall.FeelsLike;
@@ -34,6 +32,8 @@ import org.openhab.binding.openweathermap.internal.dto.onecall.OpenWeatherMapOne
 import org.openhab.binding.openweathermap.internal.dto.onecall.Rain;
 import org.openhab.binding.openweathermap.internal.dto.onecall.Snow;
 import org.openhab.binding.openweathermap.internal.dto.onecall.Temp;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.thing.Channel;
@@ -215,14 +215,14 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler
 
     @Override
     protected boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws CommunicationException, ConfigurationException {
         logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
         try {
             weatherData = connection.getOneCallAPIData(location, forecastMinutes == 0, forecastHours == 0,
                     forecastDays == 0, numberOfAlerts == 0);
             return true;
         } catch (JsonSyntaxException e) {
-            logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
+            logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
             return false;
         }
     }
index ecac85bd63bb401a62381b06e13ecd7e8b2dcfad..5adaab3c24b6c9fbf52901783d7b6a8f9e69aa4c 100644 (file)
@@ -23,13 +23,13 @@ import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapOneCallHistoryConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
 import org.openhab.binding.openweathermap.internal.dto.onecallhist.Hourly;
 import org.openhab.binding.openweathermap.internal.dto.onecallhist.OpenWeatherMapOneCallHistAPIData;
 import org.openhab.binding.openweathermap.internal.dto.onecallhist.Rain;
 import org.openhab.binding.openweathermap.internal.dto.onecallhist.Snow;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.thing.ChannelUID;
@@ -90,13 +90,13 @@ public class OpenWeatherMapOneCallHistoryHandler extends AbstractOpenWeatherMapH
 
     @Override
     protected boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws CommunicationException, ConfigurationException {
         logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
         try {
             weatherData = connection.getOneCallHistAPIData(location, day);
             return true;
         } catch (JsonSyntaxException e) {
-            logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
+            logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
             return false;
         }
     }
index 141a5896df3e1e30070f91fe95ee4acac3a16668..0180be3994de938635b551473ba56deccaf970a7 100644 (file)
@@ -22,10 +22,10 @@ import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapUVIndexConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
 import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonUVIndexData;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.thing.Channel;
 import org.openhab.core.thing.ChannelUID;
@@ -116,7 +116,7 @@ public class OpenWeatherMapUVIndexHandler extends AbstractOpenWeatherMapHandler
 
     @Override
     protected boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws CommunicationException, ConfigurationException {
         logger.debug("Update UV Index data of thing '{}'.", getThing().getUID());
         try {
             uvindexData = connection.getUVIndexData(location);
@@ -125,7 +125,7 @@ public class OpenWeatherMapUVIndexHandler extends AbstractOpenWeatherMapHandler
             }
             return true;
         } catch (JsonSyntaxException e) {
-            logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
+            logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
             return false;
         }
     }
index f0faccec36ccf5212aecbcdc7084b402ef4bdab1..6fd7ee16f23fc28aec073512731a4d3559f07529 100644 (file)
@@ -27,8 +27,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpResponseException;
 import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapWeatherAndForecastConfiguration;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
-import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
 import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
 import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonDailyForecastData;
 import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonHourlyForecastData;
@@ -37,6 +35,8 @@ import org.openhab.binding.openweathermap.internal.dto.base.Rain;
 import org.openhab.binding.openweathermap.internal.dto.base.Snow;
 import org.openhab.binding.openweathermap.internal.dto.forecast.daily.FeelsLikeTemp;
 import org.openhab.core.config.core.Configuration;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConfigurationException;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.thing.Channel;
@@ -163,7 +163,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
 
     @Override
     protected boolean requestData(OpenWeatherMapConnection connection)
-            throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
+            throws CommunicationException, ConfigurationException {
         logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
         try {
             weatherData = connection.getWeatherData(location);
@@ -173,7 +173,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
             if (forecastDays > 0) {
                 try {
                     dailyForecastData = connection.getDailyForecastData(location, forecastDays);
-                } catch (OpenWeatherMapConfigurationException e) {
+                } catch (ConfigurationException e) {
                     if (e.getCause() instanceof HttpResponseException) {
                         forecastDays = 0;
                         Configuration editConfig = editConfiguration();
@@ -193,7 +193,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
             }
             return true;
         } catch (JsonSyntaxException e) {
-            logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
+            logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
             return false;
         }
     }
index cccfcbf4715c85b6d3bdbedbb620f4425a11cd86..dde7aa2918d6ea7c06df52f57d6325b946da3fd9 100644 (file)
@@ -357,6 +357,7 @@ offline.conf-error-not-supported-onecall-number-of-minutes = The 'forecastMinute
 offline.conf-error-not-supported-onecall-number-of-hours = The 'forecastHours' parameter must be between 0 and 48.
 offline.conf-error-not-supported-onecall-number-of-days = The 'forecastDays' parameter must be between 0 and 7.
 offline.conf-error-not-supported-onecall-number-of-alerts = The 'numberOfAlerts' parameter must be greater than or equals to 0.
+offline.communication-error = An unexpected exception occurred during execution.
 
 # discovery result