File tree Expand file tree Collapse file tree 11 files changed +39
-20
lines changed
transaction/actions/gasless/providers Expand file tree Collapse file tree 11 files changed +39
-20
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Better error messages for failed requests
Original file line number Diff line number Diff line change @@ -60,8 +60,10 @@ export async function getErc721Tokens({
6060 ) ;
6161
6262 if ( ! response . ok ) {
63- response . body ?. cancel ( ) ;
64- console . error ( "Failed to fetch NFTs" ) ;
63+ const error = await response . text ( ) . catch ( ( ) => null ) ;
64+ console . error (
65+ `Failed to fetch NFTs: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
66+ ) ;
6567 return {
6668 nextCursor : undefined ,
6769 tokens : [ ] ,
Original file line number Diff line number Diff line change @@ -9,8 +9,10 @@ export async function getChains() {
99 ) ;
1010
1111 if ( ! response . ok ) {
12- response . body ?. cancel ( ) ;
13- throw new Error ( "Failed to fetch chains" ) ;
12+ const error = await response . text ( ) . catch ( ( ) => null ) ;
13+ throw new Error (
14+ `Failed to fetch chains: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
15+ ) ;
1416 }
1517
1618 return ( await response . json ( ) ) . data as ChainMetadata [ ] ;
Original file line number Diff line number Diff line change @@ -79,8 +79,10 @@ export async function getBuyWithCryptoHistory(
7979
8080 // Assuming the response directly matches the SwapResponse interface
8181 if ( ! response . ok ) {
82- response . body ?. cancel ( ) ;
83- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
82+ const error = await response . text ( ) . catch ( ( ) => null ) ;
83+ throw new Error (
84+ `HTTP error! status: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
85+ ) ;
8486 }
8587
8688 const data : BuyWithCryptoHistoryData = ( await response . json ( ) ) . result ;
Original file line number Diff line number Diff line change @@ -142,8 +142,10 @@ export async function getBuyWithCryptoStatus(
142142
143143 // Assuming the response directly matches the BuyWithCryptoStatus interface
144144 if ( ! response . ok ) {
145- response . body ?. cancel ( ) ;
146- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
145+ const error = await response . text ( ) . catch ( ( ) => null ) ;
146+ throw new Error (
147+ `HTTP error! status: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
148+ ) ;
147149 }
148150
149151 const data : BuyWithCryptoStatus = ( await response . json ( ) ) . result ;
Original file line number Diff line number Diff line change @@ -78,8 +78,10 @@ export async function getBuyWithFiatHistory(
7878
7979 // Assuming the response directly matches the BuyWithFiatStatus response interface
8080 if ( ! response . ok ) {
81- response . body ?. cancel ( ) ;
82- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
81+ const error = await response . text ( ) . catch ( ( ) => null ) ;
82+ throw new Error (
83+ `HTTP error! status: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
84+ ) ;
8385 }
8486
8587 const data : BuyWithFiatHistoryData = ( await response . json ( ) ) . result ;
Original file line number Diff line number Diff line change @@ -188,8 +188,10 @@ export async function getBuyWithFiatStatus(
188188 const response = await getClientFetch ( params . client ) ( url ) ;
189189
190190 if ( ! response . ok ) {
191- response . body ?. cancel ( ) ;
192- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
191+ const error = await response . text ( ) . catch ( ( ) => null ) ;
192+ throw new Error (
193+ `HTTP error! status: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
194+ ) ;
193195 }
194196
195197 return ( await response . json ( ) ) . result ;
Original file line number Diff line number Diff line change @@ -93,8 +93,10 @@ export async function getBuyHistory(
9393
9494 // Assuming the response directly matches the SwapResponse interface
9595 if ( ! response . ok ) {
96- response . body ?. cancel ( ) ;
97- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
96+ const error = await response . text ( ) . catch ( ( ) => null ) ;
97+ throw new Error (
98+ `HTTP error! status: ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
99+ ) ;
98100 }
99101
100102 const data : BuyHistoryData = ( await response . json ( ) ) . result ;
Original file line number Diff line number Diff line change @@ -72,9 +72,9 @@ export async function fetchRpc(
7272 } ) ;
7373
7474 if ( ! response . ok ) {
75- response . body ?. cancel ( ) ;
75+ const error = await response . text ( ) . catch ( ( ) => null ) ;
7676 throw new Error (
77- `RPC request failed with status ${ response . status } - ${ response . statusText } ` ,
77+ `RPC request failed with status ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
7878 ) ;
7979 }
8080
@@ -116,8 +116,10 @@ export async function fetchSingleRpc(
116116 } ) ;
117117
118118 if ( ! response . ok ) {
119- response . body ?. cancel ( ) ;
120- throw new Error ( `RPC request failed with status ${ response . status } ` ) ;
119+ const error = await response . text ( ) . catch ( ( ) => null ) ;
120+ throw new Error (
121+ `RPC request failed with status ${ response . status } - ${ response . statusText } : ${ error || "unknown error" } ` ,
122+ ) ;
121123 }
122124 if ( response . headers . get ( "Content-Type" ) ?. startsWith ( "application/json" ) ) {
123125 return await response . json ( ) ;
Original file line number Diff line number Diff line change @@ -139,7 +139,6 @@ export async function relayBiconomyTransaction(
139139 } ,
140140 ) ;
141141 if ( ! response . ok ) {
142- response . body ?. cancel ( ) ;
143142 throw new Error ( `Failed to send transaction: ${ await response . text ( ) } ` ) ;
144143 }
145144 const json = await response . json ( ) ;
You can’t perform that action at this time.
0 commit comments