mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[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:
parent
475709d5f6
commit
8dfb10e8e9
@ -121,9 +121,13 @@ public class ApiHandler {
|
|||||||
} else if (statusCode == Code.FORBIDDEN) {
|
} else if (statusCode == Code.FORBIDDEN) {
|
||||||
logger.debug("Fobidden, serviceReponse was {}, ", content);
|
logger.debug("Fobidden, serviceReponse was {}, ", content);
|
||||||
if (result instanceof Response<?> errorResponse) {
|
if (result instanceof Response<?> errorResponse) {
|
||||||
|
if (errorResponse.getErrorCode() == Response.ErrorCode.INSUFFICIENT_RIGHTS) {
|
||||||
|
throw new PermissionException(errorResponse.getMissingRight(), errorResponse.getMsg());
|
||||||
|
} else {
|
||||||
throw new FreeboxException(errorResponse.getErrorCode(), errorResponse.getMsg());
|
throw new FreeboxException(errorResponse.getErrorCode(), errorResponse.getMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new FreeboxException("Error '%s' requesting: %s", statusCode.getMessage(), uri.toString());
|
throw new FreeboxException("Error '%s' requesting: %s", statusCode.getMessage(), uri.toString());
|
||||||
} catch (TimeoutException | ExecutionException e) {
|
} catch (TimeoutException | ExecutionException e) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.freeboxos.internal.api;
|
package org.openhab.binding.freeboxos.internal.api;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.openhab.binding.freeboxos.internal.api.Response.ErrorCode;
|
||||||
import org.openhab.binding.freeboxos.internal.api.rest.LoginManager;
|
import org.openhab.binding.freeboxos.internal.api.rest.LoginManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,6 +27,11 @@ public class PermissionException extends FreeboxException {
|
|||||||
|
|
||||||
private final LoginManager.Permission permission;
|
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) {
|
public PermissionException(LoginManager.Permission permission, String format, Object... args) {
|
||||||
super(format, args);
|
super(format, args);
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
|
@ -26,6 +26,7 @@ import javax.measure.Unit;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
|
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.LanBrowserManager.Source;
|
||||||
import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager;
|
import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager;
|
||||||
import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager.MediaType;
|
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());
|
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) {
|
} catch (FreeboxException e) {
|
||||||
logger.warn("Error handling command: {}", e.getMessage());
|
logger.warn("Error handling command {} on channel {}: {}", command, channelUID.getId(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user