Skip to content

Commit

Permalink
[freeboxos] Enhance log warning when handling channel command fails (o…
Browse files Browse the repository at this point in the history
…penhab#17201)

* Throw PermissionException based on error code

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Aug 13, 2024
1 parent 475709d commit 8dfb10e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz,
} 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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -176,8 +177,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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());
}
}

Expand Down

0 comments on commit 8dfb10e

Please sign in to comment.