diff --git a/src/app/pages/error/error.page.html b/src/app/pages/error/error.page.html
index 68a9610..3f44061 100644
--- a/src/app/pages/error/error.page.html
+++ b/src/app/pages/error/error.page.html
@@ -8,10 +8,7 @@
{{ message }}
-
- {{ data | json }}
-
+ {{ data | json }}
diff --git a/src/extension/extension-client/ExtensionClient.ts b/src/extension/extension-client/ExtensionClient.ts
index c9c0f11..50e4555 100644
--- a/src/extension/extension-client/ExtensionClient.ts
+++ b/src/extension/extension-client/ExtensionClient.ts
@@ -320,6 +320,20 @@ export class ExtensionClient extends BeaconClient {
await this.processMessage(beaconMessage, request)
}
+ const errorData = (beaconMessage as any).errorData as unknown
+ if (
+ errorData &&
+ (
+ !Array.isArray(errorData) ||
+ !errorData.every((item) => Boolean(item.kind) && Boolean(item.id))
+ )
+ ) {
+ logger.warn(
+ 'ErrorData provided is not in correct format. It needs to be an array of RPC errors. It will not be included in the message sent to the dApp'
+ )
+ delete (beaconMessage as any).errorData
+ }
+
// TODO: Remove v1 compatibility in later version
; (beaconMessage as any).beaconId = beaconMessage.senderId
diff --git a/src/extension/extension-client/beacon-message-handler/operation-request-handler.ts b/src/extension/extension-client/beacon-message-handler/operation-request-handler.ts
index 2b29be0..8df36d5 100644
--- a/src/extension/extension-client/beacon-message-handler/operation-request-handler.ts
+++ b/src/extension/extension-client/beacon-message-handler/operation-request-handler.ts
@@ -10,6 +10,7 @@ import {
OperationResponseInput
} from '@airgap/beacon-sdk'
import { TezosWrappedOperation } from '@airgap/coinlib-core/protocols/tezos/types/TezosWrappedOperation'
+import { AxiosResponse } from 'axios'
import { LedgerSigner, LocalSigner } from 'src/extension/AirGapSigner'
import { WalletInfo, WalletType } from '../Actions'
@@ -34,17 +35,16 @@ export const operationRequestHandler: (client: ExtensionClient, logger: Logger)
let responseInput: OperationResponseInput
- const sendError: (error: Error, errorType: BeaconErrorType, errorData?: any) => Promise = async (
+ const sendError: (error: Error, errorType: BeaconErrorType) => Promise = async (
error: Error,
errorType: BeaconErrorType,
- errorData?: any
): Promise => {
- logger.log('error', error)
+ logger.log('operationRequestHandler', 'error ', error)
responseInput = {
id: operationRequest.id,
type: BeaconMessageType.OperationResponse,
errorType,
- errorData
+ errorData: (error as any as AxiosResponse).data
} as any
const response: OperationResponse = {
@@ -98,7 +98,7 @@ export const operationRequestHandler: (client: ExtensionClient, logger: Logger)
const hash: To = await to(client.operationProvider.broadcast(operationRequest.network, signedTx.res))
if (hash.err) {
- await sendError(hash.err, BeaconErrorType.TRANSACTION_INVALID_ERROR, forgedTx.err)
+ await sendError(hash.err, BeaconErrorType.TRANSACTION_INVALID_ERROR)
throw forgedTx.err
}
diff --git a/src/extension/extension-client/message-handler/ToExtensionMessageHandler.ts b/src/extension/extension-client/message-handler/ToExtensionMessageHandler.ts
index 610f94b..40c8cc5 100644
--- a/src/extension/extension-client/message-handler/ToExtensionMessageHandler.ts
+++ b/src/extension/extension-client/message-handler/ToExtensionMessageHandler.ts
@@ -18,6 +18,7 @@ import {
SignPayloadRequestOutput
} from '@airgap/beacon-sdk'
import { TezosWrappedOperation } from '@airgap/coinlib-core/protocols/tezos/types/TezosWrappedOperation'
+import { AxiosResponse } from 'axios'
import { WalletInfo } from '../Actions'
import { ExtensionClient } from '../ExtensionClient'
@@ -75,12 +76,15 @@ export class ToExtensionMessageHandler extends MessageHandler {
error: Error,
errorType: BeaconErrorType
): Promise => {
- logger.log('error', error)
+ logger.log('handle', 'error', error)
+
+ const errorData = (error as any as AxiosResponse).data.data || (error as any as AxiosResponse).data
+
const responseInput = {
id: deserialized.id,
type: BeaconMessageType.OperationResponse,
errorType,
- errorData: error
+ errorData
} as any
const response: OperationResponse = {
@@ -90,7 +94,7 @@ export class ToExtensionMessageHandler extends MessageHandler {
}
await this.client.sendToPage(response)
- const errorObject = { title: (error as any).name, message: (error as any).message, data: (error as any).data }
+ const errorObject = { title: (error as any).name, message: (error as any).message, data: errorData }
return this.client.sendToPopup({ ...data, payload: { error: errorObject } })
}
@@ -110,7 +114,7 @@ export class ToExtensionMessageHandler extends MessageHandler {
if (deserialized.type === BeaconMessageType.OperationRequest) {
// Intercept Operation request and enrich it with information
- ;(async (): Promise => {
+ ; (async (): Promise => {
const operationRequest: OperationRequestOutput = enriched.res as OperationRequestOutput
const wallet: WalletInfo | undefined = await this.client.getWalletByAddress(operationRequest.sourceAddress)
@@ -134,13 +138,8 @@ export class ToExtensionMessageHandler extends MessageHandler {
return this.client.sendToPopup({ ...data, payload: serialized })
})().catch(async (operationPrepareError: Error) => {
- if ((operationPrepareError as any).data) {
- await sendError((operationPrepareError as any).data, BeaconErrorType.TRANSACTION_INVALID_ERROR)
- logger.error('operationPrepareError', (operationPrepareError as any).data)
- } else {
- await sendError(operationPrepareError, BeaconErrorType.TRANSACTION_INVALID_ERROR)
- logger.error('operationPrepareError', operationPrepareError)
- }
+ await sendError(operationPrepareError, BeaconErrorType.TRANSACTION_INVALID_ERROR)
+ logger.error('operationPrepareError', operationPrepareError)
})
} else {
const serialized: string = await new Serializer().serialize(enriched.res)