diff --git a/src/forge-download.ts b/src/forge-download.ts index 3528f07..8ee4782 100644 --- a/src/forge-download.ts +++ b/src/forge-download.ts @@ -16,8 +16,14 @@ const ItemsApi = new ForgeSDK.ItemsApi(); * @param {string} destination * @param {ForgeSDK.AuthClient} credentials */ -exports.download = async (projectID: string, itemID: string, fileName: string, destination: string, credentials: ForgeSDK.AuthToken) => { - const storageLocation = await getStorageLocation(projectID, itemID, credentials); +exports.download = async ( + projectID: string, + itemID: string, + fileName: string, + destination: string, + credentials: ForgeSDK.AuthToken +): Promise => { + const storageLocation: string = await getStorageLocation(projectID, itemID, credentials); logger.info(`download: Downloading file "${fileName}" to ${destination}`); @@ -33,11 +39,16 @@ exports.download = async (projectID: string, itemID: string, fileName: string, d }) .catch((err: ForgeSDK.ApiError) => { logger.error(`download: Error downloading "${fileName}": ${err.statusCode}`, err); + throw new Error(err.statusMessage); }); }; -const getStorageLocation = (projectID: string, itemID: string, credentials: ForgeSDK.AuthToken) => { - return ItemsApi.getItem(projectID, itemID, config.authClient, credentials) +const getStorageLocation = ( + projectID: string, + itemID: string, + credentials: ForgeSDK.AuthToken +): Promise => { + return ItemsApi.getItem(projectID, itemID + '1', config.authClient, credentials) .then((res: ForgeSDK.ApiResponse) => { let data = res.body.included[0]; let storageID = data.relationships.storage.data.id; @@ -45,5 +56,6 @@ const getStorageLocation = (projectID: string, itemID: string, credentials: Forg return storageID; }).catch((err: ForgeSDK.ApiError) => { logger.error(`download: Unable to get storage location for ${itemID}: ${err.statusCode}`, err); + throw new Error(err.statusMessage); }); }; diff --git a/src/server.ts b/src/server.ts index a52ecdc..ef109de 100644 --- a/src/server.ts +++ b/src/server.ts @@ -177,7 +177,9 @@ const createServer = () => { //TODO: check if extension is in the name const fileName = body.payload.name; const destination = __dirname + "/file_share" + config.folderIDtoLocal[body.payload.parentFolderUrn]; - await downloader.download(config.projectID, itemID, fileName, destination, credentials); + await downloader.download(config.projectID, itemID, fileName, destination, credentials).catch((err: Error) => { + console.log(err); + }); } });