@@ -199,7 +199,7 @@ describe('usePerpsFlipPosition', () => {
199199 expect ( mockOnError ) . toHaveBeenCalledWith ( 'perps.errors.unknown' ) ;
200200 } ) ;
201201
202- it ( 'handles exceptions and logs via Logger.error ' , async ( ) => {
202+ it ( 'surfaces exception via toast and onError without double-reporting to Sentry ' , async ( ) => {
203203 const testError = new Error ( 'Network error' ) ;
204204 mockFlipPosition . mockRejectedValue ( testError ) ;
205205 const mockOnError = jest . fn ( ) ;
@@ -212,31 +212,13 @@ describe('usePerpsFlipPosition', () => {
212212 await result . current . handleFlipPosition ( mockLongPosition ) ;
213213 } ) ;
214214
215- expect ( Logger . error ) . toHaveBeenCalledWith (
216- testError ,
217- expect . objectContaining ( {
218- tags : expect . objectContaining ( {
219- feature : 'perps' ,
220- component : 'usePerpsFlipPosition' ,
221- action : 'flip_position' ,
222- operation : 'position_management' ,
223- } ) ,
224- context : expect . objectContaining ( {
225- name : 'usePerpsFlipPosition' ,
226- data : expect . objectContaining ( {
227- symbol : 'ETH' ,
228- size : '2.5' ,
229- currentDirection : 'long' ,
230- targetDirection : 'short' ,
231- positionSize : 2.5 ,
232- } ) ,
233- } ) ,
234- } ) ,
235- ) ;
215+ // Sentry reporting is handled at the controller layer; the UI hook must not duplicate it
216+ expect ( Logger . error ) . not . toHaveBeenCalled ( ) ;
217+ expect ( mockShowToast ) . toHaveBeenCalled ( ) ;
236218 expect ( mockOnError ) . toHaveBeenCalledWith ( 'Network error' ) ;
237219 } ) ;
238220
239- it ( 'handles non-Error exceptions' , async ( ) => {
221+ it ( 'handles non-Error exceptions with fallback message without double-reporting to Sentry ' , async ( ) => {
240222 mockFlipPosition . mockRejectedValue ( 'String error' ) ;
241223 const mockOnError = jest . fn ( ) ;
242224
@@ -248,19 +230,9 @@ describe('usePerpsFlipPosition', () => {
248230 await result . current . handleFlipPosition ( mockLongPosition ) ;
249231 } ) ;
250232
251- const [ loggedError , loggerContext ] = ( Logger . error as jest . Mock ) . mock
252- . calls [ 0 ] ;
253- expect ( loggedError ) . toBeInstanceOf ( Error ) ;
254- expect ( ( loggedError as Error ) . message ) . toBe ( 'String error' ) ;
255- expect ( loggerContext ) . toEqual (
256- expect . objectContaining ( {
257- context : expect . objectContaining ( {
258- data : expect . objectContaining ( {
259- rawError : 'String error' ,
260- } ) ,
261- } ) ,
262- } ) ,
263- ) ;
233+ // Sentry reporting is handled at the controller layer; the UI hook must not duplicate it
234+ expect ( Logger . error ) . not . toHaveBeenCalled ( ) ;
235+ expect ( mockShowToast ) . toHaveBeenCalled ( ) ;
264236 expect ( mockOnError ) . toHaveBeenCalledWith ( 'perps.errors.unknown' ) ;
265237 } ) ;
266238
0 commit comments