@@ -153,12 +153,11 @@ export async function requestFunding(
153153 body : JSON . stringify ( postBody ) ,
154154 } )
155155
156- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- it can be anything
157- const body = await response . json ( )
158156 if (
159157 response . ok &&
160158 response . headers . get ( 'Content-Type' ) ?. startsWith ( 'application/json' )
161159 ) {
160+ const body : unknown = await response . json ( )
162161 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- It's a FaucetWallet
163162 const classicAddress = ( body as FaucetWallet ) . account . classicAddress
164163 return processSuccessfulResponse (
@@ -168,7 +167,7 @@ export async function requestFunding(
168167 startingBalance ,
169168 )
170169 }
171- return processError ( response , body )
170+ return processError ( response )
172171}
173172
174173// 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(
206205 )
207206}
208207
209- async function processError ( response : Response , body ) : Promise < never > {
208+ interface ErrorData {
209+ body ?: unknown
210+ contentType ?: string
211+ statusCode : number
212+ }
213+
214+ async function processError ( response : Response ) : Promise < never > {
215+ const errorData : ErrorData = {
216+ contentType : response . headers . get ( 'Content-Type' ) ?? undefined ,
217+ statusCode : response . status ,
218+ }
219+ const clone = response . clone ( )
220+ try {
221+ const body : unknown = await response . json ( )
222+ errorData . body = body
223+ } catch {
224+ errorData . body = await clone . text ( )
225+ }
210226 return Promise . reject (
211- new XRPLFaucetError (
212- `Request failed: ${ JSON . stringify ( {
213- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- json response could be anything
214- body : body ?? { } ,
215- contentType : response . headers . get ( 'Content-Type' ) ,
216- statusCode : response . status ,
217- } ) } `,
218- ) ,
227+ new XRPLFaucetError ( `Request failed: ${ JSON . stringify ( errorData ) } ` ) ,
219228 )
220229}
221230
0 commit comments