mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 02:07:00 +08:00
Update collection_providers.dart
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user