use of org.eclipse.hono.client.registry.GatewayDisabledOrNotRegisteredException in project hono by eclipse.
the class AbstractProtocolAdapterBase method getRegistrationAssertion.
@Override
public final Future<RegistrationAssertion> getRegistrationAssertion(final String tenantId, final String deviceId, final Device authenticatedDevice, final SpanContext context) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
final Future<String> gatewayId = getGatewayId(tenantId, deviceId, authenticatedDevice);
return gatewayId.compose(gwId -> getRegistrationClient().assertRegistration(tenantId, deviceId, gwId, context)).onSuccess(assertion -> {
// the updateLastGateway invocation shouldn't delay or possibly fail the surrounding operation
// so don't wait for the outcome here
updateLastGateway(assertion, tenantId, deviceId, authenticatedDevice, context).onFailure(t -> {
log.warn("failed to update last gateway [tenantId: {}, deviceId: {}]", tenantId, deviceId, t);
});
}).recover(error -> {
final int errorCode = ServiceInvocationException.extractStatusCode(error);
if (errorCode == HttpURLConnection.HTTP_NOT_FOUND) {
return Future.failedFuture(new DeviceDisabledOrNotRegisteredException(tenantId, errorCode));
} else if (errorCode == HttpURLConnection.HTTP_FORBIDDEN) {
return Future.failedFuture(new GatewayDisabledOrNotRegisteredException(tenantId, errorCode));
} else {
return Future.failedFuture(error);
}
});
}
Aggregations