[freeboxos] Enhance log warning when handling channel command fails (#17201)

* Throw PermissionException based on error code

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2024-08-13 22:10:14 +02:00 committed by GitHub
parent 475709d5f6
commit 8dfb10e8e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View 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());
}
}
}

View 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;

View 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());
}
}