@@ -44,6 +44,8 @@ describe('relayerClient', () => {
4444 const data = '0x123' ;
4545
4646 ( global . fetch as jest . Mock ) . mockResolvedValue ( {
47+ ok : true ,
48+ text : ( ) => Promise . resolve ( JSON . stringify ( { result : transactionHash } ) ) ,
4749 json : ( ) => ( {
4850 result : transactionHash ,
4951 } ) ,
@@ -69,6 +71,36 @@ describe('relayerClient', () => {
6971 } ] ,
7072 } ) ;
7173 } ) ;
74+
75+ it ( 'throws HTTP error for non-ok response' , async ( ) => {
76+ const to = '0xd64b0d2d72bb1b3f18046b8a7fc6c9ee6bccd287' ;
77+ const data = '0x123' ;
78+
79+ ( global . fetch as jest . Mock ) . mockResolvedValue ( {
80+ ok : false ,
81+ status : 401 ,
82+ statusText : 'Unauthorized' ,
83+ text : ( ) => Promise . resolve ( '{"error":"invalid_token"}' ) ,
84+ } ) ;
85+
86+ await expect ( relayerClient . ethSendTransaction ( to , data ) ) . rejects . toThrow (
87+ 'Relayer HTTP error: 401. Content: "{"error":"invalid_token"}"' ,
88+ ) ;
89+ } ) ;
90+
91+ it ( 'throws JSON parse error for invalid response' , async ( ) => {
92+ const to = '0xd64b0d2d72bb1b3f18046b8a7fc6c9ee6bccd287' ;
93+ const data = '0x123' ;
94+
95+ ( global . fetch as jest . Mock ) . mockResolvedValue ( {
96+ ok : true ,
97+ text : ( ) => Promise . resolve ( 'invalid json' ) ,
98+ } ) ;
99+
100+ await expect ( relayerClient . ethSendTransaction ( to , data ) ) . rejects . toThrow (
101+ 'Relayer JSON parse error: Unexpected token \'i\', "invalid json" is not valid JSON. Content: "invalid json"' ,
102+ ) ;
103+ } ) ;
72104 } ) ;
73105
74106 describe ( 'imGetTransactionByHash' , ( ) => {
@@ -82,6 +114,8 @@ describe('relayerClient', () => {
82114 } ;
83115
84116 ( global . fetch as jest . Mock ) . mockResolvedValue ( {
117+ ok : true ,
118+ text : ( ) => Promise . resolve ( JSON . stringify ( { result : relayerTransaction } ) ) ,
85119 json : ( ) => ( {
86120 result : relayerTransaction ,
87121 } ) ,
@@ -118,6 +152,8 @@ describe('relayerClient', () => {
118152 } ] ;
119153
120154 ( global . fetch as jest . Mock ) . mockResolvedValue ( {
155+ ok : true ,
156+ text : ( ) => Promise . resolve ( JSON . stringify ( { result : feeOptions } ) ) ,
121157 json : ( ) => ( {
122158 result : feeOptions ,
123159 } ) ,
@@ -152,6 +188,8 @@ describe('relayerClient', () => {
152188 const relayerSignature = '0x123' ;
153189
154190 ( global . fetch as jest . Mock ) . mockResolvedValue ( {
191+ ok : true ,
192+ text : ( ) => Promise . resolve ( JSON . stringify ( { result : relayerSignature } ) ) ,
155193 json : ( ) => ( {
156194 result : relayerSignature ,
157195 } ) ,
@@ -186,6 +224,8 @@ describe('relayerClient', () => {
186224 const relayerSignature = '0x123' ;
187225
188226 ( global . fetch as jest . Mock ) . mockResolvedValue ( {
227+ ok : true ,
228+ text : ( ) => Promise . resolve ( JSON . stringify ( { result : relayerSignature } ) ) ,
189229 json : ( ) => ( {
190230 result : relayerSignature ,
191231 } ) ,
0 commit comments