1
- // ignore_for_file: avoid_print
2
1
import 'dart:convert' ;
3
2
import 'package:apidash_core/apidash_core.dart' ;
4
3
import 'package:flutter/services.dart' ;
@@ -307,8 +306,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
307
306
updateEnv? .call (originalEnvironmentModel, newValues);
308
307
} else {
309
308
if (scriptResult.updatedEnvironment.isNotEmpty) {
310
- print (
311
- 'Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.' );
309
+ final term = ref.read (terminalStateProvider.notifier);
310
+ final msg =
311
+ 'Pre-request script updated environment variables, but no active environment was selected to save them to.' ;
312
+ state = state.copyWith (lastError: msg);
313
+ term.logJs (
314
+ level: 'warn' ,
315
+ args: [msg],
316
+ context: 'preRequest' ,
317
+ contextRequestId: requestModel.id,
318
+ );
312
319
return requestModel;
313
320
}
314
321
return newRequestModel;
@@ -359,8 +366,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
359
366
updateEnv? .call (originalEnvironmentModel, newValues);
360
367
} else {
361
368
if (scriptResult.updatedEnvironment.isNotEmpty) {
362
- print (
363
- 'Warning: Post-response script updated environment variables, but no active environment was selected to save them to.' );
369
+ final term = ref.read (terminalStateProvider.notifier);
370
+ final msg =
371
+ 'Post-response script updated environment variables, but no active environment was selected to save them to.' ;
372
+ state = state.copyWith (lastError: msg);
373
+ term.logJs (
374
+ level: 'warn' ,
375
+ args: [msg],
376
+ context: 'postResponse' ,
377
+ contextRequestId: requestModel.id,
378
+ );
364
379
}
365
380
return requestModel;
366
381
}
@@ -375,8 +390,8 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
375
390
}
376
391
377
392
void _handleConsole (String level, dynamic args) {
393
+ final term = ref.read (terminalStateProvider.notifier);
378
394
try {
379
- final term = ref.read (terminalStateProvider.notifier);
380
395
List <String > argList = const < String > [];
381
396
if (args is List ) {
382
397
argList = args.map ((e) => e.toString ()).toList ();
@@ -398,13 +413,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
398
413
term.logJs (
399
414
level: level, args: argList, contextRequestId: _currentRequestId);
400
415
} catch (e) {
401
- print ('[JS ${level .toUpperCase ()} HANDLER ERROR]: $args , Error: $e ' );
416
+ term.logSystem (
417
+ category: 'provider' ,
418
+ message:
419
+ '[JS ${level .toUpperCase ()} HANDLER ERROR]: $args , Error: $e ' );
402
420
}
403
421
}
404
422
405
423
void _handleFatal (dynamic args) {
424
+ final term = ref.read (terminalStateProvider.notifier);
406
425
try {
407
- final term = ref.read (terminalStateProvider.notifier);
408
426
if (args is Map <String , dynamic >) {
409
427
final message = args['message' ]? .toString () ?? 'Unknown fatal error' ;
410
428
final error = args['error' ]? .toString ();
@@ -424,7 +442,9 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
424
442
contextRequestId: _currentRequestId);
425
443
}
426
444
} catch (e) {
427
- print ('[JS FATAL ERROR decoding error]: $args , Error: $e ' );
445
+ term.logSystem (
446
+ category: 'provider' ,
447
+ message: '[JS FATAL ERROR decoding error]: $args , Error: $e ' );
428
448
}
429
449
}
430
450
}
0 commit comments