Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilou242 committed Jan 13, 2025
1 parent ecb4d63 commit 721fbb5
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static ai.startree.thirdeye.ResourceUtils.badRequest;
import static ai.startree.thirdeye.ResourceUtils.ensure;
import static ai.startree.thirdeye.ResourceUtils.notFoundError;
import static ai.startree.thirdeye.spi.ThirdEyeStatus.ERR_DUPLICATE_NAME;
import static ai.startree.thirdeye.spi.util.SpiUtils.optional;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -196,7 +197,9 @@ public DataSourceApi recommend(final ThirdEyePrincipal principal) {
public List<DemoDatasetApi> getAvailableDemoDatasets(final ThirdEyeServerPrincipal principal,
final @NonNull Long dataSourceId) {
final DataSourceDTO dataSourceDto = dtoManager.findById(dataSourceId);
checkArgument(dataSourceDto != null, "Could not find datasource with id %s", dataSourceId);
if (dataSourceDto == null) {
throw notFoundError(ThirdEyeStatus.ERR_DATASOURCE_NOT_FOUND, dataSourceId);
}
authorizationManager.ensureNamespace(principal, dataSourceDto);
authorizationManager.ensureCanRead(principal, dataSourceDto);
final ThirdEyeDataSource dataSource = dataSourceCache.getDataSource(dataSourceDto);
Expand All @@ -206,7 +209,9 @@ public List<DemoDatasetApi> getAvailableDemoDatasets(final ThirdEyeServerPrincip
public ThirdEyeApi createDemoDataset(final ThirdEyeServerPrincipal principal,
final @NonNull Long dataSourceId, final @NonNull String demoDatasetId) {
final DataSourceDTO dataSourceDto = dtoManager.findById(dataSourceId);
checkArgument(dataSourceDto != null, "Could not find datasource with id %s", dataSourceId);
if (dataSourceDto == null) {
throw notFoundError(ThirdEyeStatus.ERR_DATASOURCE_NOT_FOUND, dataSourceId);
}
authorizationManager.ensureNamespace(principal, dataSourceDto);
// assuming the right to create a datasource gives the right to create a dataset in pinot
authorizationManager.ensureCanCreate(principal, dataSourceDto);
Expand Down

0 comments on commit 721fbb5

Please sign in to comment.