Skip to content

Commit

Permalink
feat: handle the case where Intune is not used / not licensed, return…
Browse files Browse the repository at this point in the history
… an empty array
  • Loading branch information
mjsprengers committed Oct 31, 2024
1 parent d4e5d3b commit bb9af2d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.blazebit.query.spi.DataFetcherException;
import com.blazebit.query.spi.DataFormat;
import com.microsoft.graph.beta.models.ManagedDevice;
import com.microsoft.graph.beta.models.odataerrors.ODataError;
import com.microsoft.graph.beta.serviceclient.GraphServiceClient;
import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -49,7 +50,17 @@ public List<ManagedDevice> fetch(DataFetchContext context) {
List<GraphServiceClient> graphClients = AzureGraphConnectorConfig.GRAPH_SERVICE_CLIENT.getAll(context);
List<ManagedDevice> list = new ArrayList<>();
for (GraphServiceClient graphClient : graphClients) {
list.addAll(graphClient.deviceManagement().managedDevices().get().getValue());
try {
list.addAll(graphClient.deviceManagement().managedDevices().get().getValue());
} catch (ODataError oDataError) {
// Check for the specific error indicating Intune is not available
if (oDataError.getMessage().contains("AADSTS500014")) {
// If the error is thrown, Intune is not in use: return an empty list
return list;
} else {
throw oDataError;
}
}
}
return list;
} catch (RuntimeException e) {
Expand Down

0 comments on commit bb9af2d

Please sign in to comment.