]> git.basschouten.com Git - openhab-addons.git/commitdiff
[freeboxos] Enhance log warning when handling channel command fails (#17201)
authorlolodomo <lg.hc@free.fr>
Tue, 13 Aug 2024 20:10:14 +0000 (22:10 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Aug 2024 20:10:14 +0000 (22:10 +0200)
* Throw PermissionException based on error code

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/ApiHandler.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/PermissionException.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ApiConsumerHandler.java

index f981bafe77b51f78296e6b5f793ae8ce541506b0..6f760e52cbb589c89fb38efd9479c46bc1f7199d 100644 (file)
@@ -121,7 +121,11 @@ public class ApiHandler {
             } else if (statusCode == Code.FORBIDDEN) {
                 logger.debug("Fobidden, serviceReponse was {}, ", content);
                 if (result instanceof Response<?> errorResponse) {
-                    throw new FreeboxException(errorResponse.getErrorCode(), errorResponse.getMsg());
+                    if (errorResponse.getErrorCode() == Response.ErrorCode.INSUFFICIENT_RIGHTS) {
+                        throw new PermissionException(errorResponse.getMissingRight(), errorResponse.getMsg());
+                    } else {
+                        throw new FreeboxException(errorResponse.getErrorCode(), errorResponse.getMsg());
+                    }
                 }
             }
 
index 2ca6f2b1b8b0a3a7c43cfc244fe846a54fefe2e5..0c512ec1d1d1f39553a1f7a0219e27e7c4a8f392 100644 (file)
@@ -13,6 +13,7 @@
 package org.openhab.binding.freeboxos.internal.api;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.freeboxos.internal.api.Response.ErrorCode;
 import org.openhab.binding.freeboxos.internal.api.rest.LoginManager;
 
 /**
@@ -26,6 +27,11 @@ public class PermissionException extends FreeboxException {
 
     private final LoginManager.Permission permission;
 
+    public PermissionException(LoginManager.Permission permission, String message) {
+        super(ErrorCode.INSUFFICIENT_RIGHTS, message);
+        this.permission = permission;
+    }
+
     public PermissionException(LoginManager.Permission permission, String format, Object... args) {
         super(format, args);
         this.permission = permission;
index 9fa6a32dd119022293d63d90cff3a65072b7a5bb..e3a4034249f58e74775587ef58abf51cd349b51d 100644 (file)
@@ -26,6 +26,7 @@ import javax.measure.Unit;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
+import org.openhab.binding.freeboxos.internal.api.PermissionException;
 import org.openhab.binding.freeboxos.internal.api.rest.LanBrowserManager.Source;
 import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager;
 import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager.MediaType;
@@ -176,8 +177,11 @@ public abstract class ApiConsumerHandler extends BaseThingHandler implements Api
                     logger.debug("Unexpected command {} on channel {}", command, channelUID.getId());
                 }
             }
+        } catch (PermissionException e) {
+            logger.warn("Missing permission {} for handling command {} on channel {}: {}", e.getPermission(), command,
+                    channelUID.getId(), e.getMessage());
         } catch (FreeboxException e) {
-            logger.warn("Error handling command: {}", e.getMessage());
+            logger.warn("Error handling command {} on channel {}: {}", command, channelUID.getId(), e.getMessage());
         }
     }