[bindings d-e] Fix exception handling (Jetty HTTP client) (#10476)

Fixes #10474

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo
2021-04-06 17:37:19 +02:00
committed by GitHub
parent fed460218e
commit 8ab37ce285
20 changed files with 73 additions and 62 deletions

View File

@@ -119,8 +119,11 @@ public class ApiAccess {
retVal = new Gson().fromJson(reply, outClass);
}
}
} catch (InterruptedException | ExecutionException e) {
} catch (ExecutionException e) {
logger.debug("Error in handling request: ", e);
} catch (InterruptedException e) {
logger.debug("Handling request interrupted: ", e);
Thread.currentThread().interrupt();
}
return retVal;

View File

@@ -48,7 +48,6 @@ public class EvohomeApiClient {
private static final String CLIENT_SECRET = "1a15cdb8-42de-407b-add0-059f92c530cb";
private final Logger logger = LoggerFactory.getLogger(EvohomeApiClient.class);
private final HttpClient httpClient;
private final EvohomeAccountConfiguration configuration;
private final ApiAccess apiAccess;
@@ -60,19 +59,9 @@ public class EvohomeApiClient {
* Creates a new API client based on the V2 API interface
*
* @param configuration The configuration of the account to use
* @throws Exception
*/
public EvohomeApiClient(EvohomeAccountConfiguration configuration, HttpClient httpClient) throws Exception {
public EvohomeApiClient(EvohomeAccountConfiguration configuration, HttpClient httpClient) {
this.configuration = configuration;
this.httpClient = httpClient;
try {
httpClient.start();
} catch (Exception e) {
logger.error("Could not start http client", e);
throw new EvohomeApiClientException("Could not start http client", e);
}
apiAccess = new ApiAccess(httpClient);
apiAccess.setApplicationId(APPLICATION_ID);
}
@@ -85,14 +74,6 @@ public class EvohomeApiClient {
useraccount = null;
locations = null;
locationsStatus = null;
if (httpClient.isStarted()) {
try {
httpClient.stop();
} catch (Exception e) {
logger.debug("Could not stop http client.", e);
}
}
}
public boolean login() {

View File

@@ -74,30 +74,22 @@ public class EvohomeAccountBridgeHandler extends BaseBridgeHandler {
configuration = getConfigAs(EvohomeAccountConfiguration.class);
if (checkConfig()) {
try {
apiClient = new EvohomeApiClient(configuration, this.httpClient);
} catch (Exception e) {
logger.error("Could not start API client", e);
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Could not create evohome API client");
}
apiClient = new EvohomeApiClient(configuration, this.httpClient);
if (apiClient != null) {
// Initialization can take a while, so kick it off on a separate thread
scheduler.schedule(() -> {
if (apiClient.login()) {
if (checkInstallationInfoHasDuplicateIds(apiClient.getInstallationInfo())) {
startRefreshTask();
} else {
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"System Information Sanity Check failed");
}
// Initialization can take a while, so kick it off on a separate thread
scheduler.schedule(() -> {
if (apiClient.login()) {
if (checkInstallationInfoHasDuplicateIds(apiClient.getInstallationInfo())) {
startRefreshTask();
} else {
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Authentication failed");
"System Information Sanity Check failed");
}
}, 0, TimeUnit.SECONDS);
}
} else {
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Authentication failed");
}
}, 0, TimeUnit.SECONDS);
}
}