diff --git a/packages/taquito/src/contract/lambda-view.ts b/packages/taquito/src/contract/lambda-view.ts index f2ff161f30..bae2ee4e93 100644 --- a/packages/taquito/src/contract/lambda-view.ts +++ b/packages/taquito/src/contract/lambda-view.ts @@ -25,10 +25,7 @@ export default class LambdaView { await this.lambdaContract.methods.default(this.voidLambda).send(); } catch (ex) { if (ex instanceof TezosOperationError) { - const lastError: any = ex.errors[ex.errors.length - 1]; - - const failedWith = lastError.with; - return failedWith; + return (ex.lastError as any).with; } else { throw ex; } diff --git a/packages/taquito/src/estimate/rpc-estimate-provider.ts b/packages/taquito/src/estimate/rpc-estimate-provider.ts index dc52dd51b7..1c730798e5 100644 --- a/packages/taquito/src/estimate/rpc-estimate-provider.ts +++ b/packages/taquito/src/estimate/rpc-estimate-provider.ts @@ -107,7 +107,11 @@ export class RPCEstimateProvider extends Provider implements EstimationProvider // Fail early in case of errors if (errors.length) { - throw new TezosOperationError(errors, 'Error occurred during estimation'); + throw new TezosOperationError( + errors, + 'Error occurred during estimation', + opResponse.contents + ); } let numberOfOps = 1; diff --git a/packages/taquito/src/operations/errors.ts b/packages/taquito/src/operations/errors.ts index cc987b0b78..2d84c39304 100644 --- a/packages/taquito/src/operations/errors.ts +++ b/packages/taquito/src/operations/errors.ts @@ -1,6 +1,7 @@ import { ParameterValidationError, RpcError, TaquitoError } from '@taquito/core'; import { MichelsonV1ExpressionBase, + OperationContentsAndResult, OperationResult, OperationResultDelegation, OperationResultOrigination, @@ -33,32 +34,37 @@ const isErrorWithMessage = (error: any): error is TezosOperationErrorWithMessage * @description Generic tezos error that will be thrown when a mistake occurs when doing an operation; more details here https://tezos.gitlab.io/api/errors.html */ export class TezosOperationError extends RpcError { - id: string; - kind: string; + public readonly lastError: TezosGenericOperationError; constructor( public readonly errors: TezosGenericOperationError[], - public readonly errorDetails?: string + public readonly errorDetails: string, + public readonly operationsWithResults: OperationContentsAndResult[] ) { super(); this.name = 'TezosOperationError'; // Last error is 'often' the one with more detail - const lastError = errors[errors.length - 1]; - this.id = lastError.id; - this.kind = lastError.kind; + this.lastError = errors[errors.length - 1]; this.message = `(${this.kind}) ${this.id}`; - if (isErrorWithMessage(lastError)) { - if (lastError.with.string) { - this.message = lastError.with.string; - } else if (lastError.with.int) { - this.message = lastError.with.int; + if (isErrorWithMessage(this.lastError)) { + if (this.lastError.with.string) { + this.message = this.lastError.with.string; + } else if (this.lastError.with.int) { + this.message = this.lastError.with.int; } else { - this.message = JSON.stringify(lastError.with); + this.message = JSON.stringify(this.lastError.with); } } } + + get id(): string { + return this.lastError.id; + } + get kind(): string { + return this.lastError.kind; + } } /** diff --git a/packages/taquito/src/provider.ts b/packages/taquito/src/provider.ts index f0809f50d9..3914b0f58f 100644 --- a/packages/taquito/src/provider.ts +++ b/packages/taquito/src/provider.ts @@ -187,7 +187,8 @@ export abstract class Provider { if (errors.length) { throw new TezosOperationError( errors, - 'Error occurred during validation simulation of operation' + 'Error occurred during validation simulation of operation', + opResponse ); }