From c2d338595d41718ee487969035a95f14da2f7e34 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 28 Oct 2025 15:43:55 -0400 Subject: [PATCH 1/4] improve faucet erroring --- packages/xrpl/src/Wallet/fundWallet.ts | 33 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/xrpl/src/Wallet/fundWallet.ts b/packages/xrpl/src/Wallet/fundWallet.ts index e39236883a..57d5503ee8 100644 --- a/packages/xrpl/src/Wallet/fundWallet.ts +++ b/packages/xrpl/src/Wallet/fundWallet.ts @@ -153,12 +153,11 @@ export async function requestFunding( body: JSON.stringify(postBody), }) - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- it can be anything - const body = await response.json() if ( response.ok && response.headers.get('Content-Type')?.startsWith('application/json') ) { + const body: unknown = await response.json() // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- It's a FaucetWallet const classicAddress = (body as FaucetWallet).account.classicAddress return processSuccessfulResponse( @@ -168,7 +167,7 @@ export async function requestFunding( startingBalance, ) } - return processError(response, body) + return processError(response) } // eslint-disable-next-line max-params -- Only used as a helper function, lines inc due to added balance. @@ -206,16 +205,26 @@ async function processSuccessfulResponse( ) } -async function processError(response: Response, body): Promise { +interface ErrorData { + body?: unknown + contentType?: string + statusCode: number +} + +async function processError(response: Response): Promise { + const errorData: ErrorData = { + contentType: response.headers.get('Content-Type') ?? undefined, + statusCode: response.status, + } + const clone = response.clone() + try { + const body: unknown = await response.json() + errorData.body = body + } catch { + errorData.body = await clone.text() + } return Promise.reject( - new XRPLFaucetError( - `Request failed: ${JSON.stringify({ - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- json response could be anything - body: body ?? {}, - contentType: response.headers.get('Content-Type'), - statusCode: response.status, - })}`, - ), + new XRPLFaucetError(`Request failed: ${JSON.stringify(errorData)}`), ) } From 5498dc1e6dab69faa4f8c3b631f9237a1cfb10ab Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 28 Oct 2025 16:59:02 -0400 Subject: [PATCH 2/4] update history --- packages/xrpl/HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 5eddeca9a8..40790267c2 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -9,6 +9,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ### Fixed * Fix incorrect type checking in `validateVaultCreate` that prevented vault creation with MPT as an asset. +* Better faucet error handling ## 4.4.2 (2025-09-25) From bccd860be5ea97d4c5219091006e5d1c6b72ae3a Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 28 Oct 2025 17:23:28 -0400 Subject: [PATCH 3/4] fix tests --- packages/xrpl/test/faucet/fundWallet.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/test/faucet/fundWallet.test.ts b/packages/xrpl/test/faucet/fundWallet.test.ts index 5a8a7b6aeb..839af4ee53 100644 --- a/packages/xrpl/test/faucet/fundWallet.test.ts +++ b/packages/xrpl/test/faucet/fundWallet.test.ts @@ -121,12 +121,13 @@ describe('fundWallet', function () { throw new Error('Error not thrown') } catch (error) { - await api.disconnect() expect(error).toEqual( new XRPLFaucetError( - 'Request failed: {"body":{"error":"Invalid amount","detail":"Must be an integer"},"contentType":"application/json; charset=utf-8","statusCode":400}', + 'Request failed: {"contentType":"application/json; charset=utf-8","statusCode":400,"body":{"error":"Invalid amount","detail":"Must be an integer"}}', ), ) + } finally { + await api.disconnect() } }) }) From 85058a202b7e234c1b8709f68d5258c9045b95d2 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 5 Dec 2025 16:50:33 -0500 Subject: [PATCH 4/4] fix history --- packages/xrpl/HISTORY.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 704f235620..1269a19922 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -5,7 +5,8 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ## Unreleased ### Fixed -* Update ripple-binary-codec to 2.5.1 to address serialization/deserialization issues in `Issue` serialized type for MPTIssue. +* Update ripple-binary-codec to 2.5.1 to address serialization/deserialization issues in `Issue` serialized type for `MPTIssue`. +* Better faucet error handling ## 4.4.3 (2025-11-07) @@ -17,7 +18,6 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Fix incorrect type checking in `validateVaultCreate` that prevented vault creation with MPT as an asset. * [Breaking change] Fix `MPTokenMetadata` type to adhere to the XLS-89 standard. Since XLS-89 is still in a forming state and undergoing changes, this breaking change is being released as a bug fix via patch version bump. If you are using `MPTokenMetadata` in your code, please verify that it adheres to the updated type definition. * [Breaking change] Fix `validateMPTokenMetadata` to correctly validate MPTokenMetadata as per XLS-89 standard. Since XLS-89 is still in a forming state and undergoing changes, this breaking change is being released as a bug fix via patch version bump. If you are using `validateMPTokenMetadata` in your code, expect it to change as per the XLS-89 standard. -* Better faucet error handling ## 4.4.2 (2025-09-25)