From 22ca6af358670584a7816aea64edbc7b6651ebba Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 23 Oct 2023 17:29:38 +0200 Subject: [PATCH] fix: js-dataverse error types --- .../repositories/DatasetJSDataverseRepository.ts | 8 ++++---- src/files/infrastructure/FileJSDataverseRepository.ts | 10 +++++----- .../repositories/DataverseInfoJSDataverseRepository.ts | 4 ++-- .../MetadataBlockInfoJSDataverseRepository.ts | 6 +++++- .../repositories/UserJSDataverseRepository.ts | 3 +-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index ea25c0aa2..78201a14c 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -4,10 +4,10 @@ import { getDataset, getDatasetCitation, getDatasetSummaryFieldNames, - WriteError, Dataset as JSDataset, getPrivateUrlDataset, - getPrivateUrlDatasetCitation + getPrivateUrlDatasetCitation, + ReadError } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' @@ -25,7 +25,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) ) - .catch((error: WriteError) => { + .catch((error: ReadError) => { if (!version) { throw new Error(error.message) } @@ -42,7 +42,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) ) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index d98b5d241..752518ac4 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -10,7 +10,7 @@ import { getDatasetFilesTotalDownloadSize, getFileDownloadCount, getFileUserPermissions, - WriteError + ReadError } from '@iqss/dataverse-client-javascript' import { FileCriteria } from '../domain/models/FileCriteria' import { DomainFileMapper } from './mappers/DomainFileMapper' @@ -39,7 +39,7 @@ export class FileJSDataverseRepository implements FileRepository { ) .then((jsFiles) => jsFiles.map((jsFile) => JSFileMapper.toFile(jsFile, datasetVersion))) .then((files) => FileJSDataverseRepository.getAllWithDownloadCount(files)) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } @@ -77,7 +77,7 @@ export class FileJSDataverseRepository implements FileRepository { .then((jsFilesCountInfo) => { return JSFileMapper.toFilesCountInfo(jsFilesCountInfo) }) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } @@ -88,7 +88,7 @@ export class FileJSDataverseRepository implements FileRepository { ): Promise { return getDatasetFilesTotalDownloadSize .execute(datasetPersistentId, datasetVersion.toString(), FileDownloadSizeMode.ARCHIVAL) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } @@ -99,7 +99,7 @@ export class FileJSDataverseRepository implements FileRepository { .then((jsFileUserPermissions) => JSFileMapper.toFileUserPermissions(id, jsFileUserPermissions) ) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } diff --git a/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts b/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts index 25024c165..f02dde979 100644 --- a/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts +++ b/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts @@ -1,4 +1,4 @@ -import { getDataverseVersion, WriteError } from '@iqss/dataverse-client-javascript' +import { getDataverseVersion, ReadError } from '@iqss/dataverse-client-javascript' import { DataverseInfoRepository } from '../../domain/repositories/DataverseInfoRepository' import { DataverseVersion } from '../../domain/models/DataverseVersion' @@ -22,7 +22,7 @@ export class DataverseInfoJSDataverseRepository implements DataverseInfoReposito .then((jsDataverseDataverseVersion: JSDataverseDataverseVersion) => DataverseInfoJSDataverseRepository.formatVersion(jsDataverseDataverseVersion) ) - .catch((error: WriteError) => { + .catch((error: ReadError) => { throw new Error(error.message) }) } diff --git a/src/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository.ts b/src/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository.ts index 38e5bb4d4..2071898c9 100644 --- a/src/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository.ts +++ b/src/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository.ts @@ -2,7 +2,8 @@ import { MetadataBlockInfoRepository } from '../../domain/repositories/MetadataB import { MetadataBlockInfo } from '../../domain/models/MetadataBlockInfo' import { getMetadataBlockByName, - MetadataBlock as JSMetadataBlockInfo + MetadataBlock as JSMetadataBlockInfo, + ReadError } from '@iqss/dataverse-client-javascript' import { JSMetadataBlockInfoMapper } from '../mappers/JSMetadataBlockInfoMapper' @@ -13,5 +14,8 @@ export class MetadataBlockInfoJSDataverseRepository implements MetadataBlockInfo .then((jsMetadataBlockInfo: JSMetadataBlockInfo) => JSMetadataBlockInfoMapper.toMetadataBlockInfo(jsMetadataBlockInfo) ) + .catch((error: ReadError) => { + throw new Error(error.message) + }) } } diff --git a/src/users/infrastructure/repositories/UserJSDataverseRepository.ts b/src/users/infrastructure/repositories/UserJSDataverseRepository.ts index 5e788f614..69ea18d64 100644 --- a/src/users/infrastructure/repositories/UserJSDataverseRepository.ts +++ b/src/users/infrastructure/repositories/UserJSDataverseRepository.ts @@ -3,8 +3,7 @@ import { AuthenticatedUser, getCurrentAuthenticatedUser } from '@iqss/dataverse-client-javascript/dist/users' -import { ReadError } from '@iqss/dataverse-client-javascript/dist/core' -import { logout, WriteError } from '@iqss/dataverse-client-javascript' +import { logout, ReadError, WriteError } from '@iqss/dataverse-client-javascript' import { UserRepository } from '../../domain/repositories/UserRepository' export class UserJSDataverseRepository implements UserRepository {