From 33b3bef93fb2dfa147022a2af154e898c88824fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Saive?= Date: Sun, 21 Jul 2019 13:23:42 +0200 Subject: [PATCH] Revert "Fixed compatibility issue on new rxjs version" --- src/infrastructure/AccountHttp.ts | 220 +++++++----------- src/infrastructure/BlockHttp.ts | 159 ++++++------- src/infrastructure/ChainHttp.ts | 31 +-- src/infrastructure/DiagnosticHttp.ts | 35 ++- src/infrastructure/Http.ts | 11 - src/infrastructure/MosaicHttp.ts | 152 ++++++------ src/infrastructure/NamespaceHttp.ts | 97 +++----- src/infrastructure/NetworkHttp.ts | 23 +- src/infrastructure/NodeHttp.ts | 42 ++-- src/infrastructure/TransactionHttp.ts | 69 ++---- src/infrastructure/api/accountRoutesApi.ts | 84 +++++-- src/infrastructure/api/blockRoutesApi.ts | 42 +++- src/infrastructure/api/chainRoutesApi.ts | 14 +- src/infrastructure/api/diagnosticRoutesApi.ts | 14 +- src/infrastructure/api/mosaicRoutesApi.ts | 21 +- src/infrastructure/api/namespaceRoutesApi.ts | 28 ++- src/infrastructure/api/networkRoutesApi.ts | 7 +- src/infrastructure/api/nodeRoutesApi.ts | 14 +- .../api/transactionRoutesApi.ts | 49 ++-- .../templates/api-single.mustache | 7 +- test/infrastructure/TransactionHttp.spec.ts | 11 +- 21 files changed, 543 insertions(+), 587 deletions(-) diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index aed431fd19..6ef6ba3fae 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map, mergeMap} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map, mergeMap} from 'rxjs/operators'; import { DtoMapping } from '../core/utils/DtoMapping'; import {AccountInfo} from '../model/account/AccountInfo'; import { AccountNames } from '../model/account/AccountNames'; @@ -35,6 +34,7 @@ import {UInt64} from '../model/UInt64'; import {AccountRepository} from './AccountRepository'; import { AccountInfoDTO, AccountNamesDTO, + AccountRestrictionsDTO, AccountRestrictionsInfoDTO, AccountRoutesApi, MosaicDTO, @@ -75,25 +75,21 @@ export class AccountHttp extends Http implements AccountRepository { * @returns Observable */ public getAccountInfo(address: Address): Observable { - return observableFrom(this.accountRoutesApi.getAccountInfo(address.plain())).pipe( - map((response: { response: ClientResponse; body: AccountInfoDTO; }) => { - const accountInfoDTO = response.body; - return new AccountInfo( - accountInfoDTO.meta, - Address.createFromEncoded(accountInfoDTO.account.address), - new UInt64(accountInfoDTO.account.addressHeight), - accountInfoDTO.account.publicKey, - new UInt64(accountInfoDTO.account.publicKeyHeight), - accountInfoDTO.account.mosaics.map((mosaicDTO) => new Mosaic( - new MosaicId(mosaicDTO.id), - new UInt64(mosaicDTO.amount), - )), - new UInt64(accountInfoDTO.account.importance), - new UInt64(accountInfoDTO.account.importanceHeight), - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.accountRoutesApi.getAccountInfo(address.plain())).pipe(map((accountInfoDTO: AccountInfoDTO) => { + return new AccountInfo( + accountInfoDTO.meta, + Address.createFromEncoded(accountInfoDTO.account.address), + new UInt64(accountInfoDTO.account.addressHeight), + accountInfoDTO.account.publicKey, + new UInt64(accountInfoDTO.account.publicKeyHeight), + accountInfoDTO.account.mosaics.map((mosaicDTO) => new Mosaic( + new MosaicId(mosaicDTO.id), + new UInt64(mosaicDTO.amount), + )), + new UInt64(accountInfoDTO.account.importance), + new UInt64(accountInfoDTO.account.importanceHeight), + ); + })); } /** @@ -103,12 +99,9 @@ export class AccountHttp extends Http implements AccountRepository { */ public getAccountRestrictions(address: Address): Observable { return observableFrom(this.accountRoutesApi.getAccountRestrictions(address.plain())) - .pipe(map((response: { response: ClientResponse; body: AccountRestrictionsInfoDTO; }) => { - const accountRestrictions = response.body; - return DtoMapping.extractAccountRestrictionFromDto(accountRestrictions); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + .pipe(map((accountRestrictions: AccountRestrictionsInfoDTO) => { + return DtoMapping.extractAccountRestrictionFromDto(accountRestrictions); + })); } /** @@ -122,14 +115,11 @@ export class AccountHttp extends Http implements AccountRepository { }; return observableFrom( this.accountRoutesApi.getAccountRestrictionsFromAccounts(accountIds)) - .pipe(map((response: { response: ClientResponse; body: AccountRestrictionsInfoDTO[]; }) => { - const accountRestrictions = response.body; - return accountRestrictions.map((restriction) => { - return DtoMapping.extractAccountRestrictionFromDto(restriction); - }); - }), - catchError((error) => throwError(error)), - ); + .pipe(map((accountRestrictions: AccountRestrictionsDTO[]) => { + return accountRestrictions.map((restriction) => { + return DtoMapping.extractAccountRestrictionFromDto(restriction); + }); + })); } /** @@ -142,25 +132,21 @@ export class AccountHttp extends Http implements AccountRepository { addresses: addresses.map((address) => address.plain()), }; return observableFrom( - this.accountRoutesApi.getAccountsInfo(accountIdsBody)).pipe( - map((response: { response: ClientResponse; body: AccountInfoDTO[]; }) => { - const accountsInfoMetaDataDTO = response.body; - return accountsInfoMetaDataDTO.map((accountInfoDTO: AccountInfoDTO) => { - return new AccountInfo( - accountInfoDTO.meta, - Address.createFromEncoded(accountInfoDTO.account.address), - new UInt64(accountInfoDTO.account.addressHeight), - accountInfoDTO.account.publicKey, - new UInt64(accountInfoDTO.account.publicKeyHeight), - accountInfoDTO.account.mosaics.map((mosaicDTO: MosaicDTO) => - new Mosaic(new MosaicId(mosaicDTO.id), new UInt64(mosaicDTO.amount))), - new UInt64(accountInfoDTO.account.importance), - new UInt64(accountInfoDTO.account.importanceHeight), - ); - }); - }), - catchError((error) => throwError(error)), - ); + this.accountRoutesApi.getAccountsInfo(accountIdsBody)).pipe(map((accountsInfoMetaDataDTO: AccountInfoDTO[]) => { + return accountsInfoMetaDataDTO.map((accountInfoDTO: AccountInfoDTO) => { + return new AccountInfo( + accountInfoDTO.meta, + Address.createFromEncoded(accountInfoDTO.account.address), + new UInt64(accountInfoDTO.account.addressHeight), + accountInfoDTO.account.publicKey, + new UInt64(accountInfoDTO.account.publicKeyHeight), + accountInfoDTO.account.mosaics.map((mosaicDTO: MosaicDTO) => + new Mosaic(new MosaicId(mosaicDTO.id), new UInt64(mosaicDTO.amount))), + new UInt64(accountInfoDTO.account.importance), + new UInt64(accountInfoDTO.account.importanceHeight), + ); + }); + })); } public getAccountsNames(addresses: Address[]): Observable { @@ -168,20 +154,16 @@ export class AccountHttp extends Http implements AccountRepository { addresses: addresses.map((address) => address.plain()), }; return observableFrom( - this.accountRoutesApi.getAccountsNames(accountIdsBody)).pipe( - map((response: { response: ClientResponse; body: AccountNamesDTO[]; }) => { - const accountNames = response.body; - return accountNames.map((accountName) => { - return new AccountNames( - Address.createFromEncoded(accountName.address), - accountName.names.map((name) => { - return new NamespaceName(new NamespaceId(name), name); - }), - ); - }); - }), - catchError((error) => throwError(error)), - ); + this.accountRoutesApi.getAccountsNames(accountIdsBody)).pipe(map((accountNames: AccountNamesDTO[]) => { + return accountNames.map((accountName) => { + return new AccountNames( + Address.createFromEncoded(accountName.address), + accountName.names.map((name) => { + return new NamespaceName(new NamespaceId(name), name); + }), + ); + }); + })); } /** * Gets a MultisigAccountInfo for an account. @@ -192,20 +174,17 @@ export class AccountHttp extends Http implements AccountRepository { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( this.accountRoutesApi.getAccountMultisig(address.plain())) - .pipe(map((response: { response: ClientResponse; body: MultisigAccountInfoDTO; }) => { - const multisigAccountInfoDTO = response.body; - return new MultisigAccountInfo( - PublicAccount.createFromPublicKey(multisigAccountInfoDTO.multisig.account, networkType), - multisigAccountInfoDTO.multisig.minApproval, - multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories - .map((cosigner) => PublicAccount.createFromPublicKey(cosigner, networkType)), - multisigAccountInfoDTO.multisig.multisigAccounts - .map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)), - ); - }), - catchError((error) => throwError(error)), - ))); + .pipe(map((multisigAccountInfoDTO: MultisigAccountInfoDTO) => { + return new MultisigAccountInfo( + PublicAccount.createFromPublicKey(multisigAccountInfoDTO.multisig.account, networkType), + multisigAccountInfoDTO.multisig.minApproval, + multisigAccountInfoDTO.multisig.minRemoval, + multisigAccountInfoDTO.multisig.cosignatories + .map((cosigner) => PublicAccount.createFromPublicKey(cosigner, networkType)), + multisigAccountInfoDTO.multisig.multisigAccounts + .map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)), + ); + })))); } /** @@ -217,28 +196,24 @@ export class AccountHttp extends Http implements AccountRepository { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( this.accountRoutesApi.getAccountMultisigGraph(address.plain())) - .pipe(map((response: { response: ClientResponse; body: MultisigAccountGraphInfoDTO[]; }) => { - const multisigAccountGraphInfosDTO = response.body; - const multisigAccounts = new Map(); - multisigAccountGraphInfosDTO.map((multisigAccountGraphInfoDTO) => { - multisigAccounts.set(multisigAccountGraphInfoDTO.level, - multisigAccountGraphInfoDTO.multisigEntries.map((multisigAccountInfoDTO) => { - return new MultisigAccountInfo( - PublicAccount.createFromPublicKey(multisigAccountInfoDTO.multisig.account, networkType), - multisigAccountInfoDTO.multisig.minApproval, - multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories - .map((cosigner) => PublicAccount.createFromPublicKey(cosigner, networkType)), - multisigAccountInfoDTO.multisig.multisigAccounts - .map((multisigAccountDTO) => - PublicAccount.createFromPublicKey(multisigAccountDTO, networkType))); - }), - ); - }); - return new MultisigAccountGraphInfo(multisigAccounts); - }), - catchError((error) => throwError(error)), - ))); + .pipe(map((multisigAccountGraphInfosDTO: MultisigAccountGraphInfoDTO[]) => { + const multisigAccounts = new Map(); + multisigAccountGraphInfosDTO.map((multisigAccountGraphInfoDTO) => { + multisigAccounts.set(multisigAccountGraphInfoDTO.level, + multisigAccountGraphInfoDTO.multisigEntries.map((multisigAccountInfoDTO) => { + return new MultisigAccountInfo( + PublicAccount.createFromPublicKey(multisigAccountInfoDTO.multisig.account, networkType), + multisigAccountInfoDTO.multisig.minApproval, + multisigAccountInfoDTO.multisig.minRemoval, + multisigAccountInfoDTO.multisig.cosignatories + .map((cosigner) => PublicAccount.createFromPublicKey(cosigner, networkType)), + multisigAccountInfoDTO.multisig.multisigAccounts + .map((multisigAccountDTO) => PublicAccount.createFromPublicKey(multisigAccountDTO, networkType))); + }), + ); + }); + return new MultisigAccountGraphInfo(multisigAccounts); + })))); } /** @@ -253,14 +228,11 @@ export class AccountHttp extends Http implements AccountRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); }); - }), - catchError((error) => throwError(error)), - ); + })); } /** @@ -276,14 +248,11 @@ export class AccountHttp extends Http implements AccountRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); }); - }), - catchError((error) => throwError(error)), - ); + })); } /** @@ -299,14 +268,11 @@ export class AccountHttp extends Http implements AccountRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); }); - }), - catchError((error) => throwError(error)), - ); + })); } /** @@ -323,14 +289,11 @@ export class AccountHttp extends Http implements AccountRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); }); - }), - catchError((error) => throwError(error)), - ); + })); } /** @@ -346,13 +309,10 @@ export class AccountHttp extends Http implements AccountRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; }); - }), - catchError((error) => throwError(error)), - ); + })); } } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index a6f4ce9bb8..f04089fb52 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map, mergeMap} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map, mergeMap} from 'rxjs/operators'; import {PublicAccount} from '../model/account/PublicAccount'; import {BlockInfo} from '../model/blockchain/BlockInfo'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; @@ -80,33 +79,29 @@ export class BlockHttp extends Http implements BlockRepository { * @returns Observable */ public getBlockByHeight(height: number): Observable { - return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe( - map((response: { response: ClientResponse; body: BlockInfoDTO; } ) => { - const blockDTO = response.body; - const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16); - return new BlockInfo( - blockDTO.meta.hash, - blockDTO.meta.generationHash, - new UInt64(blockDTO.meta.totalFee), - blockDTO.meta.numTransactions, - blockDTO.block.signature, - PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType), - networkType, - parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version - blockDTO.block.type, - new UInt64(blockDTO.block.height), - new UInt64(blockDTO.block.timestamp), - new UInt64(blockDTO.block.difficulty), - blockDTO.block.feeMultiplier, - blockDTO.block.previousBlockHash, - blockDTO.block.blockTransactionsHash, - blockDTO.block.blockReceiptsHash, - blockDTO.block.stateHash, - extractBeneficiary(blockDTO, networkType), - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe(map((blockDTO: BlockInfoDTO) => { + const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16); + return new BlockInfo( + blockDTO.meta.hash, + blockDTO.meta.generationHash, + new UInt64(blockDTO.meta.totalFee), + blockDTO.meta.numTransactions, + blockDTO.block.signature, + PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType), + networkType, + parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version + blockDTO.block.type, + new UInt64(blockDTO.block.height), + new UInt64(blockDTO.block.timestamp), + new UInt64(blockDTO.block.difficulty), + blockDTO.block.feeMultiplier, + blockDTO.block.previousBlockHash, + blockDTO.block.blockTransactionsHash, + blockDTO.block.blockReceiptsHash, + blockDTO.block.stateHash, + extractBeneficiary(blockDTO, networkType), + ); + })); } /** @@ -122,14 +117,11 @@ export class BlockHttp extends Http implements BlockRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)) - .pipe(map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => { - const transactionsDTO = response.body; + .pipe(map((transactionsDTO: TransactionInfoDTO[]) => { return transactionsDTO.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + })); } /** @@ -140,35 +132,31 @@ export class BlockHttp extends Http implements BlockRepository { */ public getBlocksByHeightWithLimit(height: number, limit: LimitType = LimitType.N_25): Observable { return observableFrom( - this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe( - map((response: { response: ClientResponse; body: BlockInfoDTO[]; }) => { - const blocksDTO = response.body; - return blocksDTO.map((blockDTO) => { - const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16); - return new BlockInfo( - blockDTO.meta.hash, - blockDTO.meta.generationHash, - new UInt64(blockDTO.meta.totalFee), - blockDTO.meta.numTransactions, - blockDTO.block.signature, - PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType), - networkType, - parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version - blockDTO.block.type, - new UInt64(blockDTO.block.height), - new UInt64(blockDTO.block.timestamp), - new UInt64(blockDTO.block.difficulty), - blockDTO.block.feeMultiplier, - blockDTO.block.previousBlockHash, - blockDTO.block.blockTransactionsHash, - blockDTO.block.blockReceiptsHash, - blockDTO.block.stateHash, - extractBeneficiary(blockDTO, networkType), - ); - }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe(map((blocksDTO: BlockInfoDTO[]) => { + return blocksDTO.map((blockDTO) => { + const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16); + return new BlockInfo( + blockDTO.meta.hash, + blockDTO.meta.generationHash, + new UInt64(blockDTO.meta.totalFee), + blockDTO.meta.numTransactions, + blockDTO.block.signature, + PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType), + networkType, + parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version + blockDTO.block.type, + new UInt64(blockDTO.block.height), + new UInt64(blockDTO.block.timestamp), + new UInt64(blockDTO.block.difficulty), + blockDTO.block.feeMultiplier, + blockDTO.block.previousBlockHash, + blockDTO.block.blockTransactionsHash, + blockDTO.block.blockReceiptsHash, + blockDTO.block.stateHash, + extractBeneficiary(blockDTO, networkType), + ); + }); + })); } /** @@ -183,18 +171,14 @@ export class BlockHttp extends Http implements BlockRepository { */ public getMerkleReceipts(height: number, hash: string): Observable { return observableFrom( - this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe( - map((response: { response: ClientResponse; body: MerkleProofInfoDTO; } ) => { - const merkleProofReceipt = response.body; - return new MerkleProofInfo( - new MerkleProofInfoPayload( - merkleProofReceipt.payload.merklePath!.map( - (payload) => new MerklePathItem(payload.position, payload.hash))), - merkleProofReceipt.type, - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(map((merkleProofReceipt: MerkleProofInfoDTO) => { + return new MerkleProofInfo( + new MerkleProofInfoPayload( + merkleProofReceipt.payload.merklePath!.map( + (payload) => new MerklePathItem(payload.position, payload.hash))), + merkleProofReceipt.type, + ); + })); } /** @@ -209,18 +193,13 @@ export class BlockHttp extends Http implements BlockRepository { */ public getMerkleTransaction(height: number, hash: string): Observable { return observableFrom( - this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe( - map((response: { response: ClientResponse; body: MerkleProofInfoDTO; } ) => { - const merkleProofTransaction = response.body; - return new MerkleProofInfo( - new MerkleProofInfoPayload( - merkleProofTransaction.payload.merklePath!.map((payload) => - new MerklePathItem(payload.position, payload.hash))), - merkleProofTransaction.type, - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(map((merkleProofTransaction: MerkleProofInfoDTO) => { + return new MerkleProofInfo( + new MerkleProofInfoPayload( + merkleProofTransaction.payload.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash))), + merkleProofTransaction.type, + ); + })); } /** @@ -233,11 +212,9 @@ export class BlockHttp extends Http implements BlockRepository { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( this.blockRoutesApi.getBlockReceipts(height)).pipe( - map((response: { response: ClientResponse; body: StatementsDTO; }) => { - const receiptDTO = response.body; + map((receiptDTO: StatementsDTO) => { return CreateStatementFromDTO(receiptDTO, networkType); }), - catchError((error) => throwError(this.errorHandling(error))), ), ), ); diff --git a/src/infrastructure/ChainHttp.ts b/src/infrastructure/ChainHttp.ts index 5b32953b6f..c791b69297 100644 --- a/src/infrastructure/ChainHttp.ts +++ b/src/infrastructure/ChainHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import {BlockchainScore} from '../model/blockchain/BlockchainScore'; import {UInt64} from '../model/UInt64'; import { BlockchainScoreDTO, @@ -51,13 +50,9 @@ export class ChainHttp extends Http implements ChainRepository { * @returns Observable */ public getBlockchainHeight(): Observable { - return observableFrom(this.chainRoutesApi.getBlockchainHeight()).pipe( - map((response: { response: ClientResponse; body: HeightInfoDTO; } ) => { - const heightDTO = response.body; - return new UInt64(heightDTO.height); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.chainRoutesApi.getBlockchainHeight()).pipe(map((heightDTO: HeightInfoDTO) => { + return new UInt64(heightDTO.height); + })); } /** @@ -65,15 +60,11 @@ export class ChainHttp extends Http implements ChainRepository { * @returns Observable */ public getBlockchainScore(): Observable { - return observableFrom(this.chainRoutesApi.getBlockchainScore()).pipe( - map((response: { response: ClientResponse; body: BlockchainScoreDTO; } ) => { - const blockchainScoreDTO = response.body; - return new BlockchainScore( - new UInt64(blockchainScoreDTO.scoreLow), - new UInt64(blockchainScoreDTO.scoreHigh), - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.chainRoutesApi.getBlockchainScore()).pipe(map((blockchainScoreDTO: BlockchainScoreDTO) => { + return new BlockchainScore( + new UInt64(blockchainScoreDTO.scoreLow), + new UInt64(blockchainScoreDTO.scoreHigh), + ); + })); } } diff --git a/src/infrastructure/DiagnosticHttp.ts b/src/infrastructure/DiagnosticHttp.ts index 0af049602a..be17dbcf5e 100644 --- a/src/infrastructure/DiagnosticHttp.ts +++ b/src/infrastructure/DiagnosticHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo'; import { ServerInfo } from '../model/diagnostic/ServerInfo'; import { DiagnosticRoutesApi, ServerDTO, StorageInfoDTO } from './api'; @@ -50,17 +49,13 @@ export class DiagnosticHttp extends Http implements DiagnosticRepository { */ public getDiagnosticStorage(): Observable { return observableFrom( - this.diagnosticRoutesApi.getDiagnosticStorage()).pipe( - map((response: { response: ClientResponse; body: StorageInfoDTO; } ) => { - const blockchainStorageInfoDTO = response.body; - return new BlockchainStorageInfo( - blockchainStorageInfoDTO.numBlocks, - blockchainStorageInfoDTO.numTransactions, - blockchainStorageInfoDTO.numAccounts, - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.diagnosticRoutesApi.getDiagnosticStorage()).pipe(map((blockchainStorageInfoDTO: StorageInfoDTO) => { + return new BlockchainStorageInfo( + blockchainStorageInfoDTO.numBlocks, + blockchainStorageInfoDTO.numTransactions, + blockchainStorageInfoDTO.numAccounts, + ); + })); } /** @@ -69,13 +64,9 @@ export class DiagnosticHttp extends Http implements DiagnosticRepository { */ public getServerInfo(): Observable { return observableFrom( - this.diagnosticRoutesApi.getServerInfo()).pipe( - map((response: { response: ClientResponse; body: ServerDTO; } ) => { - const serverDTO = response.body; - return new ServerInfo(serverDTO.serverInfo.restVersion, - serverDTO.serverInfo.sdkVersion); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.diagnosticRoutesApi.getServerInfo()).pipe(map((serverDTO: ServerDTO) => { + return new ServerInfo(serverDTO.serverInfo.restVersion, + serverDTO.serverInfo.sdkVersion); + })); } } diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 7df9e615ae..7185797d17 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -57,15 +57,4 @@ export abstract class Http { order: queryParams ? queryParams.order : undefined, }; } - - errorHandling(error: any): Error { - if (error.response && error.response.statusCode && error.response.body) { - const formattedError = { - statusCode: error.response.statusCode, - errorDetails: error.response.body, - }; - return new Error(JSON.stringify(formattedError)); - } - return new Error(error); - } } diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index 104aee210b..1d56765c0b 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map, mergeMap} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map, mergeMap} from 'rxjs/operators'; import {PublicAccount} from '../model/account/PublicAccount'; import {MosaicId} from '../model/mosaic/MosaicId'; import {MosaicInfo} from '../model/mosaic/MosaicInfo'; @@ -62,38 +61,33 @@ export class MosaicHttp extends Http implements MosaicRepository { public getMosaic(mosaicId: MosaicId): Observable { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( - this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe( - map((response: { response: ClientResponse; body: MosaicInfoDTO; } ) => { - const mosaicInfoDTO = response.body; - let mosaicFlag; - let divisibility; - let duration; - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value) { - mosaicFlag = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value; - } - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value) { - divisibility = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; - } - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value) { - duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; - } - return new MosaicInfo( - mosaicInfoDTO.meta.id, - new MosaicId(mosaicInfoDTO.mosaic.mosaicId), - new UInt64(mosaicInfoDTO.mosaic.supply), - new UInt64(mosaicInfoDTO.mosaic.height), - PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType), - mosaicInfoDTO.mosaic.revision, - new MosaicProperties( - mosaicFlag ? new UInt64(mosaicFlag) : UInt64.fromUint(0), - (divisibility ? new UInt64(divisibility) : UInt64.fromUint(0)).compact(), - duration ? new UInt64(duration) : undefined, - ), - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - )), - ); + this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe(map((mosaicInfoDTO: MosaicInfoDTO) => { + let mosaicFlag; + let divisibility; + let duration; + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value) { + mosaicFlag = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value; + } + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value) { + divisibility = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; + } + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value) { + duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; + } + return new MosaicInfo( + mosaicInfoDTO.meta.id, + new MosaicId(mosaicInfoDTO.mosaic.mosaicId), + new UInt64(mosaicInfoDTO.mosaic.supply), + new UInt64(mosaicInfoDTO.mosaic.height), + PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType), + mosaicInfoDTO.mosaic.revision, + new MosaicProperties( + mosaicFlag ? new UInt64(mosaicFlag) : UInt64.fromUint(0), + (divisibility ? new UInt64(divisibility) : UInt64.fromUint(0)).compact(), + duration ? new UInt64(duration) : undefined, + ), + ); + })))); } /** @@ -107,41 +101,35 @@ export class MosaicHttp extends Http implements MosaicRepository { }; return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( - this.mosaicRoutesApi.getMosaics(mosaicIdsBody)).pipe( - map((response: { response: ClientResponse; body: MosaicInfoDTO[]; }) => { - const mosaicInfosDTO = response.body; - return mosaicInfosDTO.map((mosaicInfoDTO) => { - let mosaicFlag; - let divisibility; - let duration; - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value) { - mosaicFlag = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value; - } - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value) { - divisibility = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; - } - if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value) { - duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value; - } - return new MosaicInfo( - mosaicInfoDTO.meta.id, - new MosaicId(mosaicInfoDTO.mosaic.mosaicId), - new UInt64(mosaicInfoDTO.mosaic.supply), - new UInt64(mosaicInfoDTO.mosaic.height), - PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType), - mosaicInfoDTO.mosaic.revision, - new MosaicProperties( - mosaicFlag ? new UInt64(mosaicFlag) : UInt64.fromUint(0), - (divisibility ? new UInt64(divisibility) : UInt64.fromUint(0)).compact(), - duration ? new UInt64(duration) : undefined, - ), - ); - }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - ), - ); + this.mosaicRoutesApi.getMosaics(mosaicIdsBody)).pipe(map((mosaicInfosDTO: MosaicInfoDTO[]) => { + return mosaicInfosDTO.map((mosaicInfoDTO) => { + let mosaicFlag; + let divisibility; + let duration; + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value) { + mosaicFlag = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.MosaicFlags].value; + } + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value) { + divisibility = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; + } + if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value) { + duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value; + } + return new MosaicInfo( + mosaicInfoDTO.meta.id, + new MosaicId(mosaicInfoDTO.mosaic.mosaicId), + new UInt64(mosaicInfoDTO.mosaic.supply), + new UInt64(mosaicInfoDTO.mosaic.height), + PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType), + mosaicInfoDTO.mosaic.revision, + new MosaicProperties( + mosaicFlag ? new UInt64(mosaicFlag) : UInt64.fromUint(0), + (divisibility ? new UInt64(divisibility) : UInt64.fromUint(0)).compact(), + duration ? new UInt64(duration) : undefined, + ), + ); + }); + })))); } /** @@ -155,19 +143,15 @@ export class MosaicHttp extends Http implements MosaicRepository { mosaicIds: mosaicIds.map((id) => id.toHex()), }; return observableFrom( - this.mosaicRoutesApi.getMosaicsNames(mosaicIdsBody)).pipe( - map((response: { response: ClientResponse; body: MosaicNamesDTO[]; }) => { - const mosaics = response.body; - return mosaics.map((mosaic) => { - return new MosaicNames( - new MosaicId(mosaic.mosaicId), - mosaic.names.map((name) => { - return new NamespaceName(new NamespaceId(name), name); - }), - ); - }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.mosaicRoutesApi.getMosaicsNames(mosaicIdsBody)).pipe(map((mosaics: MosaicNamesDTO[]) => { + return mosaics.map((mosaic) => { + return new MosaicNames( + new MosaicId(mosaic.mosaicId), + mosaic.names.map((name) => { + return new NamespaceName(new NamespaceId(name), name); + }), + ); + }); + })); } } diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 4d695f44bc..64ad0e94af 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map, mergeMap} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map, mergeMap} from 'rxjs/operators'; import {Convert as convert, RawAddress as AddressLibrary} from '../core/format'; import {Address} from '../model/account/Address'; import {PublicAccount} from '../model/account/PublicAccount'; @@ -66,27 +65,21 @@ export class NamespaceHttp extends Http implements NamespaceRepository { public getNamespace(namespaceId: NamespaceId): Observable { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( - this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( - map((response: { response: ClientResponse; body: NamespaceInfoDTO; } ) => { - const namespaceInfoDTO = response.body; - return new NamespaceInfo( - namespaceInfoDTO.meta.active, - namespaceInfoDTO.meta.index, - namespaceInfoDTO.meta.id, - namespaceInfoDTO.namespace.type as number, - namespaceInfoDTO.namespace.depth, - this.extractLevels(namespaceInfoDTO.namespace), - new NamespaceId(namespaceInfoDTO.namespace.parentId), - PublicAccount.createFromPublicKey(namespaceInfoDTO.namespace.owner, networkType), - new UInt64(namespaceInfoDTO.namespace.startHeight), - new UInt64(namespaceInfoDTO.namespace.endHeight), - this.extractAlias(namespaceInfoDTO.namespace), - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - ), - ); + this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe(map((namespaceInfoDTO: NamespaceInfoDTO) => { + return new NamespaceInfo( + namespaceInfoDTO.meta.active, + namespaceInfoDTO.meta.index, + namespaceInfoDTO.meta.id, + namespaceInfoDTO.namespace.type as number, + namespaceInfoDTO.namespace.depth, + this.extractLevels(namespaceInfoDTO.namespace), + new NamespaceId(namespaceInfoDTO.namespace.parentId), + PublicAccount.createFromPublicKey(namespaceInfoDTO.namespace.owner, networkType), + new UInt64(namespaceInfoDTO.namespace.startHeight), + new UInt64(namespaceInfoDTO.namespace.endHeight), + this.extractAlias(namespaceInfoDTO.namespace), + ); + })))); } /** @@ -103,8 +96,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: NamespaceInfoDTO[]; }) => { - const namespaceInfosDTO = response.body; + map((namespaceInfosDTO: NamespaceInfoDTO[]) => { return namespaceInfosDTO.map((namespaceInfoDTO) => { return new NamespaceInfo( namespaceInfoDTO.meta.active, @@ -120,10 +112,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.extractAlias(namespaceInfoDTO.namespace), ); }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - )); + })))); } /** @@ -143,8 +132,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)).pipe( - map((response: { response: ClientResponse; body: NamespaceInfoDTO[]; }) => { - const namespaceInfosDTO = response.body; + map((namespaceInfosDTO: NamespaceInfoDTO[]) => { return namespaceInfosDTO.map((namespaceInfoDTO) => { return new NamespaceInfo( namespaceInfoDTO.meta.active, @@ -160,10 +148,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.extractAlias(namespaceInfoDTO.namespace), ); }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - )); + })))); } /** @@ -176,19 +161,15 @@ export class NamespaceHttp extends Http implements NamespaceRepository { namespaceIds: namespaceIds.map((id) => id.toHex()), }; return observableFrom( - this.namespaceRoutesApi.getNamespacesNames(namespaceIdsBody)).pipe( - map((response: { response: ClientResponse; body: NamespaceNameDTO[]; } ) => { - const namespaceNamesDTO = response.body; - return namespaceNamesDTO.map((namespaceNameDTO) => { - return new NamespaceName( - new NamespaceId(namespaceNameDTO.namespaceId), - namespaceNameDTO.name, - namespaceNameDTO.parentId ? new NamespaceId(namespaceNameDTO.parentId) : undefined, - ); - }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.namespaceRoutesApi.getNamespacesNames(namespaceIdsBody)).pipe(map((namespaceNamesDTO: NamespaceNameDTO[]) => { + return namespaceNamesDTO.map((namespaceNameDTO) => { + return new NamespaceName( + new NamespaceId(namespaceNameDTO.namespaceId), + namespaceNameDTO.name, + namespaceNameDTO.parentId ? new NamespaceId(namespaceNameDTO.parentId) : undefined, + ); + }); + })); } /** @@ -200,8 +181,8 @@ export class NamespaceHttp extends Http implements NamespaceRepository { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( - map((response: { response: ClientResponse; body: NamespaceInfoDTO; } ) => { - const namespaceInfoDTO = response.body; + map((namespaceInfoDTO: NamespaceInfoDTO) => { + if (namespaceInfoDTO.namespace === undefined) { // forward catapult-rest error throw namespaceInfoDTO; @@ -213,10 +194,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { throw new Error('No mosaicId is linked to namespace \'' + namespaceInfoDTO.namespace.level0 + '\''); } return new MosaicId(namespaceInfoDTO.namespace.alias.mosaicId); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - )); + })))); } /** @@ -228,8 +206,8 @@ export class NamespaceHttp extends Http implements NamespaceRepository { return this.getNetworkTypeObservable().pipe( mergeMap((networkType) => observableFrom( this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( - map((response: { response: ClientResponse; body: NamespaceInfoDTO; } ) => { - const namespaceInfoDTO = response.body; + map((namespaceInfoDTO: NamespaceInfoDTO) => { + if (namespaceInfoDTO.namespace === undefined) { // forward catapult-rest error throw namespaceInfoDTO; @@ -244,10 +222,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { const addressDecoded = namespaceInfoDTO.namespace.alias.address; const address = AddressLibrary.addressToString(convert.hexToUint8(addressDecoded)); return Address.createFromRawAddress(address); - }), - catchError((error) => throwError(this.errorHandling(error))), - ), - )); + })))); } private extractLevels(namespace: any): NamespaceId[] { diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index a635710304..cbdc53ee9a 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import {NetworkType} from '../model/blockchain/NetworkType'; import { NetworkRoutesApi, NetworkTypeDTO } from './api'; import {Http} from './Http'; @@ -50,16 +49,12 @@ export class NetworkHttp extends Http implements NetworkRepository { * @return network type enum. */ public getNetworkType(): Observable { - return observableFrom(this.networkRoutesApi.getNetworkType()).pipe( - map((response: { response: ClientResponse; body: NetworkTypeDTO; } ) => { - const networkTypeDTO = response.body; - if (networkTypeDTO.name === 'mijinTest') { - return NetworkType.MIJIN_TEST; - } else { - throw new Error('network ' + networkTypeDTO.name + ' is not supported yet by the sdk'); - } - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.networkRoutesApi.getNetworkType()).pipe(map((networkTypeDTO: NetworkTypeDTO) => { + if (networkTypeDTO.name === 'mijinTest') { + return NetworkType.MIJIN_TEST; + } else { + throw new Error('network ' + networkTypeDTO.name + ' is not supported yet by the sdk'); + } + })); } } diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 81f81a8d25..7a29ea3388 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; +import {from as observableFrom, Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import { NodeInfo } from '../model/node/NodeInfo'; import { NodeTime } from '../model/node/NodeTime'; import { NodeInfoDTO, NodeRoutesApi, NodeTimeDTO } from './api'; @@ -50,21 +49,17 @@ export class NodeHttp extends Http implements NodeRepository { * @summary Get the node information */ public getNodeInfo(): Observable { - return observableFrom(this.nodeRoutesApi.getNodeInfo()).pipe( - map((response: { response: ClientResponse; body: NodeInfoDTO; } ) => { - const nodeInfoDTO = response.body; - return new NodeInfo( - nodeInfoDTO.publicKey, - nodeInfoDTO.port, - nodeInfoDTO.networkIdentifier, - nodeInfoDTO.version, - nodeInfoDTO.roles as number, - nodeInfoDTO.host, - nodeInfoDTO.friendlyName, - ); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.nodeRoutesApi.getNodeInfo()).pipe(map((nodeInfoDTO: NodeInfoDTO) => { + return new NodeInfo( + nodeInfoDTO.publicKey, + nodeInfoDTO.port, + nodeInfoDTO.networkIdentifier, + nodeInfoDTO.version, + nodeInfoDTO.roles as number, + nodeInfoDTO.host, + nodeInfoDTO.friendlyName, + ); + })); } /** @@ -72,13 +67,8 @@ export class NodeHttp extends Http implements NodeRepository { * @summary Get the node time */ public getNodeTime(): Observable { - return observableFrom(this.nodeRoutesApi.getNodeTime()).pipe( - map((response: { response: ClientResponse; body: NodeTimeDTO; } ) => { - const nodeTimeDTO = response.body; - return new NodeTime(nodeTimeDTO.communicationTimestamps.sendTimestamp, - nodeTimeDTO.communicationTimestamps.receiveTimestamp); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + return observableFrom(this.nodeRoutesApi.getNodeTime()).pipe(map((nodeTimeDTO: NodeTimeDTO) => { + return new NodeTime(nodeTimeDTO.communicationTimestamps.sendTimestamp, nodeTimeDTO.communicationTimestamps.receiveTimestamp); + })); } } diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index c96c863910..332ada1e85 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; import * as requestPromise from 'request-promise-native'; -import {from as observableFrom, Observable, throwError} from 'rxjs'; +import {from as observableFrom, Observable, throwError as observableThrowError} from 'rxjs'; import {catchError, map, mergeMap} from 'rxjs/operators'; import {PublicAccount} from '../model/account/PublicAccount'; import {CosignatureSignedTransaction} from '../model/transaction/CosignatureSignedTransaction'; @@ -87,15 +86,11 @@ export class TransactionHttp extends Http implements TransactionRepository { transactionIds, }; return observableFrom( - this.transactionRoutesApi.getTransactions(transactionIdsBody)).pipe( - map((response: { response: ClientResponse; body: TransactionInfoDTO[]; } ) => { - const transactionsDTO = response.body; - return transactionsDTO.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - }); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.transactionRoutesApi.getTransactions(transactionIdsBody)).pipe(map((transactionsDTO: TransactionInfoDTO[]) => { + return transactionsDTO.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + }); + })); } /** @@ -105,17 +100,14 @@ export class TransactionHttp extends Http implements TransactionRepository { */ public getTransactionStatus(transactionHash: string): Observable { return observableFrom(this.transactionRoutesApi.getTransactionStatus(transactionHash)).pipe( - map((response: { response: ClientResponse; body: TransactionStatusDTO; } ) => { - const transactionStatusDTO = response.body; + map((transactionStatusDTO: TransactionStatusDTO) => { return new TransactionStatus( transactionStatusDTO.status, transactionStatusDTO.group, transactionStatusDTO.hash, transactionStatusDTO.deadline ? Deadline.createFromDTO(transactionStatusDTO.deadline) : undefined, transactionStatusDTO.height ? new UInt64(transactionStatusDTO.height) : undefined); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + })); } /** @@ -129,8 +121,7 @@ export class TransactionHttp extends Http implements TransactionRepository { }; return observableFrom( this.transactionRoutesApi.getTransactionsStatuses(transactionHashesBody)).pipe( - map((response: { response: ClientResponse; body: TransactionStatusDTO[]; }) => { - const transactionStatusesDTO = response.body; + map((transactionStatusesDTO: TransactionStatusDTO[]) => { return transactionStatusesDTO.map((transactionStatusDTO) => { return new TransactionStatus( transactionStatusDTO.status, @@ -139,9 +130,7 @@ export class TransactionHttp extends Http implements TransactionRepository { transactionStatusDTO.deadline ? Deadline.createFromDTO(transactionStatusDTO.deadline) : undefined, transactionStatusDTO.height ? new UInt64(transactionStatusDTO.height) : undefined); }); - }), - catchError((error) => throwError(error.error.errorMessage)), - ); + })); } /** @@ -151,12 +140,9 @@ export class TransactionHttp extends Http implements TransactionRepository { */ public announce(signedTransaction: SignedTransaction): Observable { return observableFrom(this.transactionRoutesApi.announceTransaction(signedTransaction)).pipe( - map((response: { response: ClientResponse; body: AnnounceTransactionInfoDTO; } ) => { - const transactionAnnounceResponseDTO = response.body; + map((transactionAnnounceResponseDTO: AnnounceTransactionInfoDTO) => { return new TransactionAnnounceResponse(transactionAnnounceResponseDTO.message); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + })); } /** @@ -166,15 +152,14 @@ export class TransactionHttp extends Http implements TransactionRepository { */ public announceAggregateBonded(signedTransaction: SignedTransaction): Observable { if (signedTransaction.type !== TransactionType.AGGREGATE_BONDED) { - throw new Error('Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); + return observableFrom(new Promise((resolve, reject) => { + reject('Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); + })); } return observableFrom(this.transactionRoutesApi.announcePartialTransaction(signedTransaction)).pipe( - map((response: { response: ClientResponse; body: AnnounceTransactionInfoDTO; } ) => { - const transactionAnnounceResponseDTO = response.body; + map((transactionAnnounceResponseDTO: AnnounceTransactionInfoDTO) => { return new TransactionAnnounceResponse(transactionAnnounceResponseDTO.message); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + })); } /** @@ -185,12 +170,9 @@ export class TransactionHttp extends Http implements TransactionRepository { public announceAggregateBondedCosignature( cosignatureSignedTransaction: CosignatureSignedTransaction): Observable { return observableFrom(this.transactionRoutesApi.announceCosignatureTransaction(cosignatureSignedTransaction)).pipe( - map((response: { response: ClientResponse; body: AnnounceTransactionInfoDTO; } ) => { - const transactionAnnounceResponseDTO = response.body; + map((transactionAnnounceResponseDTO: AnnounceTransactionInfoDTO) => { return new TransactionAnnounceResponse(transactionAnnounceResponseDTO.message); - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + })); } public announceSync(signedTx: SignedTransaction): Observable { @@ -216,9 +198,9 @@ export class TransactionHttp extends Http implements TransactionRepository { } }), catchError((err) => { if (err.statusCode === 405) { - return throwError('non sync server'); + return observableThrowError('non sync server'); } - return throwError(err); + return observableThrowError(err); })); } @@ -236,15 +218,14 @@ export class TransactionHttp extends Http implements TransactionRepository { // now read block details return observableFrom(this.blockRoutesApi.getBlockByHeight(uintHeight.compact())).pipe( - map((response: { response: ClientResponse; body: BlockInfoDTO; } ) => { - const blockDTO = response.body; + map((blockDTO: BlockInfoDTO) => { + // @see https://nemtech.github.io/concepts/transaction.html#fees // effective_fee = feeMultiplier x transaction::size return blockDTO.block.feeMultiplier * transaction.size; - }), - catchError((error) => throwError(this.errorHandling(error)))); + })); }), catchError((err) => { - return throwError(err); + return observableThrowError(err); })); } } diff --git a/src/infrastructure/api/accountRoutesApi.ts b/src/infrastructure/api/accountRoutesApi.ts index a4c378b15f..529245b7a5 100644 --- a/src/infrastructure/api/accountRoutesApi.ts +++ b/src/infrastructure/api/accountRoutesApi.ts @@ -136,9 +136,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "AccountInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -190,9 +193,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "MultisigAccountInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -244,9 +250,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -298,9 +307,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "AccountRestrictionsInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -352,9 +364,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -406,9 +421,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -460,9 +478,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -529,9 +550,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -598,9 +622,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -667,9 +694,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -736,9 +766,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -805,9 +838,12 @@ export class AccountRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/blockRoutesApi.ts b/src/infrastructure/api/blockRoutesApi.ts index eafea7acf8..881fb16997 100644 --- a/src/infrastructure/api/blockRoutesApi.ts +++ b/src/infrastructure/api/blockRoutesApi.ts @@ -133,9 +133,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "BlockInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -187,9 +190,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "StatementsDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -251,9 +257,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -312,9 +321,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -373,9 +385,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "MerkleProofInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -434,9 +449,12 @@ export class BlockRoutesApi { } else { body = ObjectSerializer.deserialize(body, "MerkleProofInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/chainRoutesApi.ts b/src/infrastructure/api/chainRoutesApi.ts index e2697992b4..4e0706620c 100644 --- a/src/infrastructure/api/chainRoutesApi.ts +++ b/src/infrastructure/api/chainRoutesApi.ts @@ -124,9 +124,12 @@ export class ChainRoutesApi { } else { body = ObjectSerializer.deserialize(body, "HeightInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -171,9 +174,12 @@ export class ChainRoutesApi { } else { body = ObjectSerializer.deserialize(body, "BlockchainScoreDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/diagnosticRoutesApi.ts b/src/infrastructure/api/diagnosticRoutesApi.ts index 01daa002d8..e70a25623f 100644 --- a/src/infrastructure/api/diagnosticRoutesApi.ts +++ b/src/infrastructure/api/diagnosticRoutesApi.ts @@ -124,9 +124,12 @@ export class DiagnosticRoutesApi { } else { body = ObjectSerializer.deserialize(body, "StorageInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -171,9 +174,12 @@ export class DiagnosticRoutesApi { } else { body = ObjectSerializer.deserialize(body, "ServerDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/mosaicRoutesApi.ts b/src/infrastructure/api/mosaicRoutesApi.ts index 00e398b6b6..dfb0e36a8b 100644 --- a/src/infrastructure/api/mosaicRoutesApi.ts +++ b/src/infrastructure/api/mosaicRoutesApi.ts @@ -132,9 +132,12 @@ export class MosaicRoutesApi { } else { body = ObjectSerializer.deserialize(body, "MosaicInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -186,9 +189,12 @@ export class MosaicRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -240,9 +246,12 @@ export class MosaicRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/namespaceRoutesApi.ts b/src/infrastructure/api/namespaceRoutesApi.ts index 9559ef2f13..7ce0824c7b 100644 --- a/src/infrastructure/api/namespaceRoutesApi.ts +++ b/src/infrastructure/api/namespaceRoutesApi.ts @@ -133,9 +133,12 @@ export class NamespaceRoutesApi { } else { body = ObjectSerializer.deserialize(body, "NamespaceInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -197,9 +200,12 @@ export class NamespaceRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -261,9 +267,12 @@ export class NamespaceRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -315,9 +324,12 @@ export class NamespaceRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/networkRoutesApi.ts b/src/infrastructure/api/networkRoutesApi.ts index 3c574d8c46..1e9fa0422c 100644 --- a/src/infrastructure/api/networkRoutesApi.ts +++ b/src/infrastructure/api/networkRoutesApi.ts @@ -123,9 +123,12 @@ export class NetworkRoutesApi { } else { body = ObjectSerializer.deserialize(body, "NetworkTypeDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/nodeRoutesApi.ts b/src/infrastructure/api/nodeRoutesApi.ts index 456a05ad64..cd2b0ca19b 100644 --- a/src/infrastructure/api/nodeRoutesApi.ts +++ b/src/infrastructure/api/nodeRoutesApi.ts @@ -124,9 +124,12 @@ export class NodeRoutesApi { } else { body = ObjectSerializer.deserialize(body, "NodeInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -171,9 +174,12 @@ export class NodeRoutesApi { } else { body = ObjectSerializer.deserialize(body, "NodeTimeDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/api/transactionRoutesApi.ts b/src/infrastructure/api/transactionRoutesApi.ts index 0a3abdd119..39618d7377 100644 --- a/src/infrastructure/api/transactionRoutesApi.ts +++ b/src/infrastructure/api/transactionRoutesApi.ts @@ -136,9 +136,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "AnnounceTransactionInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -190,9 +193,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "AnnounceTransactionInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -244,9 +250,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "AnnounceTransactionInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -298,9 +307,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "TransactionInfoDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -352,9 +364,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "TransactionStatusDTO"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -406,9 +421,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); @@ -460,9 +478,12 @@ export class TransactionRoutesApi { } else { body = ObjectSerializer.deserialize(body, "Array"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/src/infrastructure/templates/api-single.mustache b/src/infrastructure/templates/api-single.mustache index 9dd163676f..c90274237c 100755 --- a/src/infrastructure/templates/api-single.mustache +++ b/src/infrastructure/templates/api-single.mustache @@ -219,9 +219,12 @@ export class {{classname}} { body = ObjectSerializer.deserialize(body, "{{{returnType}}}"); {{/returnType}} if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response, body }); + resolve(body); } else { - reject({ response, body }); + reject({ + statusCode: response.statusCode, + statusMessage: response.statusMessage + }); } } }); diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 40107dae10..5a45c7d440 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -46,10 +46,13 @@ describe('TransactionHttp', () => { const signedTx = account.sign(aggTx, generationHash); const trnsHttp = new TransactionHttp(NIS2_URL); - expect(() => { - trnsHttp.announceAggregateBonded(signedTx) + return trnsHttp.announceAggregateBonded(signedTx) .toPromise() - .then(); - }).to.throw(Error, 'Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); + .then(() => { + throw new Error('Should be called'); + }) + .catch((reason) => { + expect(reason.toString()).to.be.equal('Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); + }); }); });