Skip to content

Commit 5b74a2e

Browse files
fix(wallet-gateway-remote): improve JsCantonError handling (#1014)
* feat(wallet-ui-components): persist last used custom kernel in discovery Signed-off-by: Alex Matson <[email protected]> * fix(wallet-gateway-remote): improve JsCantonError handling Signed-off-by: Alex Matson <[email protected]> * use logger Signed-off-by: Alex Matson <[email protected]> --------- Signed-off-by: Alex Matson <[email protected]>
1 parent 2fd1101 commit 5b74a2e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

core/ledger-client/src/ledger-api-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ export async function retryable<T>(
437437

438438
// Helper for differentiating ledger errors from others and satisfying TS when checking error properties
439439
export const isJsCantonError = (e: unknown): e is JsCantonError =>
440-
typeof e === 'object' && e !== null && 'status' in e && 'errorCategory' in e
440+
typeof e === 'object' &&
441+
e !== null &&
442+
'code' in e &&
443+
'cause' in e &&
444+
'errorCategory' in e
441445

442446
export const asJsCantonError = (e: unknown): JsCantonError => {
443447
if (isJsCantonError(e)) {

wallet-gateway/remote/src/middleware/jsonRpcHandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
JsonRpcResponse,
1515
jsonRpcResponse,
1616
} from '@canton-network/core-types'
17+
import { isJsCantonError } from '@canton-network/core-ledger-client'
1718

1819
interface JsonRpcHttpOptions<T> {
1920
logger: Logger
@@ -52,6 +53,14 @@ const handleRpcError = (
5253
return [httpCode, jsonRpcResponse(id, response)]
5354
}
5455

56+
if (isJsCantonError(error)) {
57+
response.error = {
58+
code: rpcErrors.internal().code,
59+
message: error.cause,
60+
data: error,
61+
}
62+
}
63+
5564
if (error instanceof Error) {
5665
response.error.message = error.message
5766
} else if (typeof error === 'string') {

wallet-gateway/remote/src/user-api/controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,8 @@ export const userController = (
504504

505505
return res
506506
} catch (error) {
507-
throw new Error(
508-
'Failed to submit transaction: ' + error
509-
)
507+
logger.error(error, 'Failed to submit transaction')
508+
throw error
510509
}
511510
}
512511
case SigningProvider.WALLET_KERNEL: {

0 commit comments

Comments
 (0)