handle owners not found in v2 endpoint
@@ -10,7 +10,9 @@ import {
IPartyProps,
IUserEntityMap
} from 'wherehows-web/typings/api/datasets/party-entities';
+import { ApiResponseStatus } from 'wherehows-web/utils/api';
import { datasetUrlById, datasetUrlByUrn } from 'wherehows-web/utils/api/datasets/shared';
+import { ApiError } from 'wherehows-web/utils/api/errors/errors';
import { getJSON, postJSON } from 'wherehows-web/utils/api/fetcher';
import { getApiRoot, ApiStatus } from 'wherehows-web/utils/api/shared';
import { arrayFilter, arrayMap } from 'wherehows-web/utils/array';
@@ -120,8 +122,18 @@ const ownersWithModifiedTimeAsDate = arrayMap(ownerWithModifiedTimeAsDate);
* @return {Promise<Array<IOwner>>}
*/
const readDatasetOwnersByUrn = async (urn: string): Promise<Array<IOwner>> => {
- const { owners = [] } = await getJSON<Pick<IOwnerResponse, 'owners'>>({ url: datasetOwnersUrlByUrn(urn) });
+ let owners: Array<IOwner> = [];
+
+ try {
+ ({ owners = [] } = await getJSON<Pick<IOwnerResponse, 'owners'>>({ url: datasetOwnersUrlByUrn(urn) }));
return ownersWithModifiedTimeAsDate(owners);
+ } catch (e) {
+ if (e instanceof ApiError && e.status === ApiResponseStatus.NotFound) {
+ return owners;
+ } else {
+ throw e;
+ }
+ }
};
/**
