mirror of
https://github.com/foss42/apidash.git
synced 2025-11-30 09:48:58 +08:00
Update collection_providers.dart
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:better_networking/better_networking.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
@@ -351,61 +350,18 @@ class CollectionStateNotifier
|
||||
executionRequestModel.httpRequestModel!);
|
||||
}
|
||||
|
||||
// Terminal: Add validation logging
|
||||
// Terminal
|
||||
final terminal = ref.read(terminalStateProvider.notifier);
|
||||
|
||||
// Check for empty or invalid URL
|
||||
if (substitutedHttpRequestModel.url.trim().isEmpty) {
|
||||
|
||||
var valRes = getValidationResult(substitutedHttpRequestModel);
|
||||
if (valRes != null) {
|
||||
terminal.logSystem(
|
||||
category: 'validation',
|
||||
message: 'Request URL is empty. Please provide a valid URL.',
|
||||
message: valRes,
|
||||
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
|
||||
final logId = terminal.startNetwork(
|
||||
|
||||
Reference in New Issue
Block a user