feat: enhance cURL error messages with detailed guidance for users

This commit is contained in:
Udhay-Adithya
2025-09-26 17:13:14 +05:30
parent 896aa23ad3
commit efab7c1ec3

View File

@@ -494,8 +494,9 @@ class ChatViewmodel extends StateNotifier<ChatState> {
final curl = CurlImportService.tryParseCurl(trimmed); final curl = CurlImportService.tryParseCurl(trimmed);
if (curl == null) { if (curl == null) {
_appendSystem( _appendSystem(
'{"explnation":"Sorry, I couldn\'t parse that cURL command. Please verify it starts with `curl ` and is complete.","actions":[]}', 'I couldn\'t parse that cURL command. Please check that it:\n- Starts with `curl `\n- Has balanced quotes (wrap JSON bodies in single quotes)\n- Uses backslashes for multi-line commands (if any)\n\nFix the command and paste it again below.\n\nExample:\n\ncurl -X POST https://api.apidash.dev/users \\\n -H \'Content-Type: application/json\'',
ChatMessageType.importCurl); ChatMessageType.importCurl,
);
return; return;
} }
final currentCtx = _currentRequestContext(); final currentCtx = _currentRequestContext();
@@ -584,7 +585,8 @@ class ChatViewmodel extends StateNotifier<ChatState> {
} catch (e) { } catch (e) {
debugPrint('[cURL] Exception: $e'); debugPrint('[cURL] Exception: $e');
final safe = e.toString().replaceAll('"', "'"); final safe = e.toString().replaceAll('"', "'");
_appendSystem('{"explnation":"Parsing failed: $safe","actions":[]}', _appendSystem(
'Parsing failed: $safe. Please adjust the command (ensure it starts with `curl ` and quotes/escapes are correct) and paste it again.',
ChatMessageType.importCurl); ChatMessageType.importCurl);
} finally { } finally {
state = state.copyWith( state = state.copyWith(