mirror of
https://github.com/foss42/apidash.git
synced 2025-11-30 17:59:18 +08:00
request validation utils
This commit is contained in:
@@ -8,4 +8,5 @@ export 'http_utils.dart';
|
||||
export 'js_utils.dart';
|
||||
export 'save_utils.dart';
|
||||
export 'ui_utils.dart';
|
||||
export 'validation_utils.dart';
|
||||
export 'window_utils.dart';
|
||||
|
||||
18
lib/utils/validation_utils.dart
Normal file
18
lib/utils/validation_utils.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
|
||||
String? getValidationResult(HttpRequestModel requestModel) {
|
||||
if (requestModel.url.trim().isEmpty) {
|
||||
return 'Request URL is empty. Please provide a valid URL.';
|
||||
}
|
||||
if (requestModel.method == HTTPVerb.get && requestModel.hasAnyBody) {
|
||||
return 'GET request contains a body. This is not supported.';
|
||||
}
|
||||
if (requestModel.hasJsonData) {
|
||||
try {
|
||||
kJsonDecoder.convert(requestModel.body!);
|
||||
} catch (e) {
|
||||
return 'Invalid JSON in request body: ${e.toString()}';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user