From a380a40b4545058b22aa924a58d6428f48d570f3 Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem Date: Thu, 22 Oct 2026 07:54:39 +0100 Subject: [PATCH 1/2] test(stellar): cover contract error mapping --- server/src/services/contractErrors.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 server/src/services/contractErrors.test.ts diff --git a/server/src/services/contractErrors.test.ts b/server/src/services/contractErrors.test.ts new file mode 100644 index 0000000..76a776d --- /dev/null +++ b/server/src/services/contractErrors.test.ts @@ -0,0 +1,15 @@ +import { ContractError, TradeNotFoundError, UnauthorizedContractError, parseContractError } from "./contractErrors"; + +describe("contract error mapping", () => { + it("maps Soroban numeric codes to actionable typed errors", () => { + expect(parseContractError(new Error("Error(Contract, #3)"))).toBeInstanceOf(TradeNotFoundError); + expect(parseContractError("ContractError(2)")).toBeInstanceOf(UnauthorizedContractError); + }); + + it("uses a safe typed fallback for unknown codes and unrelated failures", () => { + const unknown = parseContractError("Error(Contract, #999)"); + expect(unknown).toBeInstanceOf(ContractError); + expect(unknown?.message).toContain("Unknown contract error"); + expect(parseContractError(new Error("network unavailable"))).toBeNull(); + }); +}); From 8b228d7f71c91087b36999b6e4cc57e2cf732c6c Mon Sep 17 00:00:00 2001 From: sa-salami <332581866+sa-salami@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:03:16 +0100 Subject: [PATCH 2/2] fix(stellar): hide unknown contract internals --- server/src/services/contractErrors.test.ts | 2 +- server/src/services/contractErrors.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/services/contractErrors.test.ts b/server/src/services/contractErrors.test.ts index 76a776d..73cb92f 100644 --- a/server/src/services/contractErrors.test.ts +++ b/server/src/services/contractErrors.test.ts @@ -9,7 +9,7 @@ describe("contract error mapping", () => { it("uses a safe typed fallback for unknown codes and unrelated failures", () => { const unknown = parseContractError("Error(Contract, #999)"); expect(unknown).toBeInstanceOf(ContractError); - expect(unknown?.message).toContain("Unknown contract error"); + expect(unknown?.message).toContain("could not be completed"); expect(parseContractError(new Error("network unavailable"))).toBeNull(); }); }); diff --git a/server/src/services/contractErrors.ts b/server/src/services/contractErrors.ts index f8f93d2..26e01f0 100644 --- a/server/src/services/contractErrors.ts +++ b/server/src/services/contractErrors.ts @@ -339,5 +339,5 @@ function instantiate(code: number): ContractError { return new Ctor(); } // Unknown code — return a generic ContractError so callers still get a typed object - return new ContractError(`Unknown contract error (code ${code})`, code); + return new ContractError("The transaction could not be completed. Please try again or contact support.", code); }