Update collection_providers.dart

This commit is contained in:
Ankit Mahato
2025-11-17 06:24:35 +05:30
parent 1112e3d6e3
commit db65c07dec

View File

@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_core/apidash_core.dart';
import 'package:better_networking/better_networking.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
@@ -351,62 +350,19 @@ class CollectionStateNotifier
executionRequestModel.httpRequestModel!); executionRequestModel.httpRequestModel!);
} }
// Terminal: Add validation logging // Terminal
final terminal = ref.read(terminalStateProvider.notifier); final terminal = ref.read(terminalStateProvider.notifier);
// Check for empty or invalid URL var valRes = getValidationResult(substitutedHttpRequestModel);
if (substitutedHttpRequestModel.url.trim().isEmpty) { if (valRes != null) {
terminal.logSystem( terminal.logSystem(
category: 'validation', category: 'validation',
message: 'Request URL is empty. Please provide a valid URL.', message: valRes,
level: TerminalLevel.error, level: TerminalLevel.error,
tags: ['request-validation', 'empty-url'],
); );
ref.read(showTerminalBadgeProvider.notifier).state = true;
} }
// Check for GET request with body
if (substitutedHttpRequestModel.method == HTTPVerb.get &&
substitutedHttpRequestModel.body != null &&
substitutedHttpRequestModel.body!.trim().isNotEmpty) {
terminal.logSystem(
category: 'validation',
message: 'GET request contains a body. This may not be supported by all servers.',
level: TerminalLevel.warn,
tags: ['request-validation', 'get-with-body'],
);
}
// Check for invalid JSON in request body
if (substitutedHttpRequestModel.body != null &&
substitutedHttpRequestModel.body!.trim().isNotEmpty &&
substitutedHttpRequestModel.bodyContentType == ContentType.json) {
try {
kJsonDecoder.convert(substitutedHttpRequestModel.body!);
// Log successful JSON validation for debugging
terminal.logSystem(
category: 'validation',
message: 'Request body contains valid JSON.',
level: TerminalLevel.debug,
tags: ['request-validation', 'valid-json'],
);
} catch (e) {
terminal.logSystem(
category: 'validation',
message: 'Invalid JSON in request body: ${e.toString()}',
level: TerminalLevel.error,
tags: ['request-validation', 'invalid-json'],
);
}
}
// Log general request validation info
terminal.logSystem(
category: 'validation',
message: 'Request validation completed for ${substitutedHttpRequestModel.method.name.toUpperCase()} ${substitutedHttpRequestModel.url}',
level: TerminalLevel.info,
tags: ['request-validation', 'completed'],
);
// Terminal: start network log // Terminal: start network log
final logId = terminal.startNetwork( final logId = terminal.startNetwork(
apiType: executionRequestModel.apiType, apiType: executionRequestModel.apiType,