diff --git a/src/common/mint-utils.ts b/src/common/mint-utils.ts index a0cb354..8d8c3af 100644 --- a/src/common/mint-utils.ts +++ b/src/common/mint-utils.ts @@ -24,19 +24,10 @@ export async function dataNFTDataStreamAdvertise( dataNftStreamUrlEncrypted: data.encryptedMessage }; } else { - throw new Error('Issue with data marshal generate payload'); - // throw new ErrFailedOperation(this.dataNFTDataStreamAdvertise.name); + throw new Error('Issue with data marshal generating payload'); } } catch (error) { throw error; - // if (error instanceof Error) { - // throw new ErrFailedOperation( - // this.dataNFTDataStreamAdvertise.name, - // error - // ); - // } else { - // throw new ErrFailedOperation(this.dataNFTDataStreamAdvertise.name); - // } } } @@ -54,7 +45,6 @@ export async function storeToIpfs( res = await nftstorage.storeDirectory(dir); } catch (error) { throw error; - // throw new ErrFailedOperation(this.storeToIpfs.name); } return { imageOnIpfsUrl: `https://ipfs.io/ipfs/${res}/image.png`, diff --git a/src/minter.ts b/src/minter.ts index a59aa13..1382dd8 100644 --- a/src/minter.ts +++ b/src/minter.ts @@ -83,7 +83,8 @@ export abstract class Minter { return new BooleanValue(returnValue).valueOf(); } else { throw new ErrContractQuery( - 'Error while retrieving the contract pause state' + 'viewContractPauseState', + returnCode.toString() ); } } diff --git a/src/nft-minter.ts b/src/nft-minter.ts index 599b9cc..810a142 100644 --- a/src/nft-minter.ts +++ b/src/nft-minter.ts @@ -25,7 +25,11 @@ import { storeToIpfs } from './common/mint-utils'; import { ContractConfiguration } from './interfaces'; -import { ErrArgumentNotSet } from './errors'; +import { + ErrArgumentNotSet, + ErrAttributeNotSet, + ErrContractQuery +} from './errors'; export class NftMinter extends Minter { /** @@ -206,10 +210,6 @@ export class NftMinter extends Minter { if (!allPassed) { throw new Error(`Params have validation issues = ${validationMessages}`); - // throw new ErrFailedOperation( - // this.mint.name, - // new Error(`params have validation issues = ${validationMessages}`) - // ); } // E: run any format specific validation... @@ -220,11 +220,6 @@ export class NftMinter extends Minter { await checkUrlIsUp(dataMarshalUrl + '/health-check', [200]); } catch (error) { throw error; - // if (error instanceof Error) { - // throw new ErrFailedOperation(this.mint.name, error); - // } else { - // throw new ErrFailedOperation(this.mint.name); - // } } let imageOnIpfsUrl: string; @@ -257,11 +252,10 @@ export class NftMinter extends Minter { metadataOnIpfsUrl = metadataIpfsUrl; } else { if (!traitsUrl) { - throw new Error('Traits URL is required when using custom image'); - // throw new ErrArgumentNotSet( - // 'traitsUrl', - // 'Traits URL is required when using custom image' - // ); + throw new ErrArgumentNotSet( + 'traitsUrl', + 'Traits URL is required when using custom image' + ); } await checkTraitsUrl(traitsUrl); @@ -459,10 +453,10 @@ export class NftMinter extends Minter { }; return contractConfiguration; } else { - throw new Error('Error while retrieving the contract pause state'); - // throw new ErrContractQuery( - // 'Error while retrieving the contract pause state' - // ); + throw new ErrContractQuery( + 'viewContractConfiguration', + returnCode.toString() + ); } } @@ -486,12 +480,7 @@ export class NftMinter extends Minter { ); return addressesWithTransferRole; } else { - throw new Error( - 'Error while retrieving the addresses with transfer roles' - ); - // throw new ErrContractQuery( - // 'Error while retrieving the addresses with transfer roles' - // ); + throw new ErrContractQuery('viewTransferRoles', returnCode.toString()); } } @@ -515,12 +504,10 @@ export class NftMinter extends Minter { ); return addressesWithUpdateAttributesRole; } else { - throw new Error( - 'Error while retrieving the addresses with update attributes roles' + throw new ErrContractQuery( + 'viewUpdateAttributesRoles', + returnCode.toString() ); - // throw new ErrContractQuery( - // 'Error while retrieving the addresses with update attributes roles' - // ); } } } diff --git a/src/sft-minter.ts b/src/sft-minter.ts index 99604fb..43b2db1 100644 --- a/src/sft-minter.ts +++ b/src/sft-minter.ts @@ -28,6 +28,7 @@ import { dataNFTDataStreamAdvertise, storeToIpfs } from './common/mint-utils'; +import { ErrArgumentNotSet } from './errors'; export class SftMinter extends Minter { /** @@ -44,8 +45,6 @@ export class SftMinter extends Minter { ); } - // [TO DO] Initialize the contract for sft minter - /** * Creates an initialize contract transaction for the contract * @param senderAddress The address of the sender, must be the admin of the contract @@ -202,10 +201,6 @@ export class SftMinter extends Minter { if (!allPassed) { throw new Error(`Params have validation issues = ${validationMessages}`); - // throw new ErrFailedOperation( - // this.mint.name, - // new Error(`params have validation issues = ${validationMessages}`) - // ); } // E: run any format specific validation... @@ -216,11 +211,6 @@ export class SftMinter extends Minter { await checkUrlIsUp(dataMarshalUrl + '/health-check', [200]); } catch (error) { throw error; - // if (error instanceof Error) { - // throw new ErrFailedOperation(this.mint.name, error); - // } else { - // throw new ErrFailedOperation(this.mint.name); - // } } let imageOnIpfsUrl: string; @@ -231,13 +221,10 @@ export class SftMinter extends Minter { if (!imageUrl) { if (!nftStorageToken) { - throw new Error( + throw new ErrArgumentNotSet( + 'nftStorageToken', 'NFT Storage token is required when not using custom image and traits' ); - // throw new ErrArgumentNotSet( - // 'nftStorageToken', - // 'NFT Storage token is required when not using custom image and traits' - // ); } const { image, traits } = await createFileFromUrl( `${this.imageServiceUrl}/v1/generateNFTArt?hash=${dataNftHash}`, @@ -256,11 +243,10 @@ export class SftMinter extends Minter { metadataOnIpfsUrl = metadataIpfsUrl; } else { if (!traitsUrl) { - throw new Error('Traits URL is required when using custom image'); - // throw new ErrArgumentNotSet( - // 'traitsUrl', - // 'Traits URL is required when using custom image' - // ); + throw new ErrArgumentNotSet( + 'traitsUrl', + 'Traits URL is required when using custom image' + ); } await checkTraitsUrl(traitsUrl); diff --git a/tests/minter.test.ts b/tests/sftminter.test.ts similarity index 100% rename from tests/minter.test.ts rename to tests/sftminter.test.ts