@@ -99,11 +99,22 @@ export class LitRelay implements IRelay {
9999 } ) ;
100100
101101 if ( response . status < 200 || response . status >= 400 ) {
102- this . #logger. info (
103- 'Something wrong with the API call' ,
104- await response . json ( )
102+ const responseBody = await response . json ( ) ;
103+ this . #logger. info ( {
104+ msg : 'Something wrong with the API call' ,
105+ responseBody,
106+ } ) ;
107+ throw new NetworkError (
108+ {
109+ info : {
110+ route : `${ this . relayUrl } ${ this . mintRoute } ` ,
111+ responseStatus : response . status ,
112+ responseStatusText : response . statusText ,
113+ responseBody,
114+ } ,
115+ } ,
116+ 'Unable to mint PKP through relay server'
105117 ) ;
106- throw new Error ( 'Unable to mint PKP through relay server' ) ;
107118 } else {
108119 const resBody = await response . json ( ) ;
109120 this . #logger. info ( 'Successfully initiated minting PKP with relayer' ) ;
@@ -240,11 +251,20 @@ export class LitRelay implements IRelay {
240251 ) ;
241252
242253 if ( response . status < 200 || response . status >= 400 ) {
243- this . #logger. info (
244- 'Something wrong with the API call' ,
245- await response . json ( )
246- ) ;
247- throw new Error (
254+ const responseBody = await response . json ( ) ;
255+ this . #logger. info ( {
256+ msg : 'Something wrong with the API call' ,
257+ responseBody,
258+ } ) ;
259+ throw new NetworkError (
260+ {
261+ info : {
262+ route : `${ this . relayUrl } /auth/status/${ requestId } ` ,
263+ responseStatus : response . status ,
264+ responseStatusText : response . statusText ,
265+ responseBody,
266+ } ,
267+ } ,
248268 `Unable to poll the status of this mint PKP transaction: ${ requestId } `
249269 ) ;
250270 }
@@ -258,7 +278,17 @@ export class LitRelay implements IRelay {
258278 msg : 'Something wrong with the API call' ,
259279 error : resBody . error ,
260280 } ) ;
261- throw new Error ( resBody . error ) ;
281+ throw new NetworkError (
282+ {
283+ info : {
284+ route : `${ this . relayUrl } /auth/status/${ requestId } ` ,
285+ responseStatus : response . status ,
286+ responseStatusText : response . statusText ,
287+ resBody,
288+ } ,
289+ } ,
290+ resBody . error
291+ ) ;
262292 } else if ( resBody . status === 'Succeeded' ) {
263293 // exit loop since success
264294 this . #logger. info ( { msg : 'Successfully authed' , resBody } ) ;
@@ -270,7 +300,14 @@ export class LitRelay implements IRelay {
270300 }
271301
272302 // at this point, polling ended and still no success, set failure status
273- throw new Error ( 'Polling for mint PKP transaction status timed out' ) ;
303+ throw new NetworkError (
304+ {
305+ info : {
306+ route : `${ this . relayUrl } /auth/status/${ requestId } ` ,
307+ } ,
308+ } ,
309+ 'Polling for mint PKP transaction status timed out'
310+ ) ;
274311 }
275312
276313 /**
@@ -291,11 +328,22 @@ export class LitRelay implements IRelay {
291328 } ) ;
292329
293330 if ( response . status < 200 || response . status >= 400 ) {
294- this . #logger. warn (
295- 'Something wrong with the API call' ,
296- await response . json ( )
331+ const resBody = await response . json ( ) ;
332+ this . #logger. warn ( {
333+ msg : 'Something wrong with the API call' ,
334+ resBody,
335+ } ) ;
336+ throw new NetworkError (
337+ {
338+ info : {
339+ route : `${ this . relayUrl } ${ this . fetchRoute } ` ,
340+ responseStatus : response . status ,
341+ responseStatusText : response . statusText ,
342+ resBody,
343+ } ,
344+ } ,
345+ 'Unable to fetch PKPs through relay server'
297346 ) ;
298- throw new Error ( 'Unable to fetch PKPs through relay server' ) ;
299347 } else {
300348 const resBody = await response . json ( ) ;
301349 this . #logger. info ( 'Successfully fetched PKPs with relayer' ) ;
@@ -322,7 +370,16 @@ export class LitRelay implements IRelay {
322370 } ,
323371 } ) ;
324372 if ( response . status < 200 || response . status >= 400 ) {
325- throw new Error ( `Unable to generate registration options: ${ response } ` ) ;
373+ throw new NetworkError (
374+ {
375+ info : {
376+ route : `${ this . relayUrl } ${ this . fetchRoute } ` ,
377+ responseStatus : response . status ,
378+ responseStatusText : response . statusText ,
379+ } ,
380+ } ,
381+ `Unable to generate registration options: ${ response } `
382+ ) ;
326383 }
327384 const registrationOptions = await response . json ( ) ;
328385 return registrationOptions ;
0 commit comments