Skip to content

Commit

Permalink
fix(frontend): handling null aspects in AspectType (#2860)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe-lyons authored Jul 10, 2021
1 parent 94fd17a commit 95b73c4
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.linkedin.entity.client.AspectClient;
import com.linkedin.metadata.aspect.VersionedAspect;
import com.linkedin.r2.RemoteInvocationException;
import com.linkedin.restli.client.RestLiResponseException;
import graphql.execution.DataFetcherResult;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -31,6 +32,13 @@ public List<DataFetcherResult<Aspect>> batchLoad(@Nonnull List<VersionedAspectKe
VersionedAspect entity = _aspectClient.getAspect(key.getUrn(), key.getAspectName(), key.getVersion());
return DataFetcherResult.<Aspect>newResult().data(AspectMapper.map(entity)).build();
} catch (RemoteInvocationException e) {
if (e instanceof RestLiResponseException) {
// if no aspect is found, restli will return a 404 rather than null
// https://linkedin.github.io/rest.li/user_guide/restli_server#returning-nulls
if(((RestLiResponseException) e).getStatus() == 404) {
return DataFetcherResult.<Aspect>newResult().data(null).build();
}
}
throw new RuntimeException(String.format("Failed to load Aspect for entity %s", key.getUrn()), e);
}
}).collect(Collectors.toList());
Expand Down

0 comments on commit 95b73c4

Please sign in to comment.