mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +01:00
Show helpful toast if someone hits a 404
This commit is contained in:
@@ -20,7 +20,8 @@ class ChatService {
|
|||||||
return await api.post(
|
return await api.post(
|
||||||
'agent/tasks/$taskId/steps', stepRequestBody.toJson());
|
'agent/tasks/$taskId/steps', stepRequestBody.toJson());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to execute step: $e');
|
// TODO: We are bubbling up the full response. Revisit this.
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class TaskService {
|
|||||||
try {
|
try {
|
||||||
return await api.post('agent/tasks', taskRequestBody.toJson());
|
return await api.post('agent/tasks', taskRequestBody.toJson());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to create a new task: $e');
|
// TODO: We are bubbling up the full response. Revisit this.
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ class RestApiUtility {
|
|||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
return json.decode(response.body);
|
return json.decode(response.body);
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to post data');
|
// TODO: We are bubbling up the full response to show better errors on the UI.
|
||||||
|
// Let's put some thought into how we would like to structure this.
|
||||||
|
throw response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +68,6 @@ class RestApiUtility {
|
|||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
return json.decode(response.body);
|
return json.decode(response.body);
|
||||||
} else {
|
} else {
|
||||||
print(response.statusCode);
|
|
||||||
print(response.body);
|
|
||||||
throw Exception('Failed to update data with PUT request');
|
throw Exception('Failed to update data with PUT request');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ class ChatViewModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print("Chats added for task ID: $_currentTaskId");
|
print("Chats added for task ID: $_currentTaskId");
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
// TODO: Bubble up errors to UI
|
// TODO: We are bubbling up the full response. Revisit this.
|
||||||
print("Error sending chat: $error");
|
rethrow;
|
||||||
// TODO: Handle additional error scenarios or log them as required
|
// TODO: Handle additional error scenarios or log them as required
|
||||||
} finally {
|
} finally {
|
||||||
_isWaitingForAgentResponse = false;
|
_isWaitingForAgentResponse = false;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class TaskViewModel with ChangeNotifier {
|
|||||||
|
|
||||||
/// Adds a task and returns its ID.
|
/// Adds a task and returns its ID.
|
||||||
Future<String> createTask(String title) async {
|
Future<String> createTask(String title) async {
|
||||||
|
try {
|
||||||
final newTask = TaskRequestBody(input: title);
|
final newTask = TaskRequestBody(input: title);
|
||||||
// Add to data source
|
// Add to data source
|
||||||
final createdTask = await _taskService.createTask(newTask);
|
final createdTask = await _taskService.createTask(newTask);
|
||||||
@@ -38,7 +39,11 @@ class TaskViewModel with ChangeNotifier {
|
|||||||
final taskId = newTaskObject.id;
|
final taskId = newTaskObject.id;
|
||||||
print("Task $taskId created successfully!");
|
print("Task $taskId created successfully!");
|
||||||
|
|
||||||
return newTaskObject.id; // Return the ID of the new task
|
return newTaskObject.id;
|
||||||
|
} catch (e) {
|
||||||
|
// TODO: We are bubbling up the full response. Revisit this.
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a task.
|
/// Deletes a task.
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import 'package:auto_gpt_flutter_client/views/chat/loading_indicator.dart';
|
|||||||
import 'package:auto_gpt_flutter_client/views/chat/user_message_tile.dart';
|
import 'package:auto_gpt_flutter_client/views/chat/user_message_tile.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
class ChatView extends StatefulWidget {
|
class ChatView extends StatefulWidget {
|
||||||
final ChatViewModel viewModel;
|
final ChatViewModel viewModel;
|
||||||
@@ -118,21 +120,40 @@ class _ChatViewState extends State<ChatView> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ChatInputField(
|
child: ChatInputField(
|
||||||
onSendPressed: (message) async {
|
onSendPressed: (message) async {
|
||||||
|
try {
|
||||||
if (widget.viewModel.currentTaskId != null) {
|
if (widget.viewModel.currentTaskId != null) {
|
||||||
widget.viewModel.sendChatMessage(
|
widget.viewModel.sendChatMessage(
|
||||||
(message == "") ? null : message,
|
(message == "") ? null : message,
|
||||||
continuousModeSteps:
|
continuousModeSteps: Provider.of<SettingsViewModel>(
|
||||||
Provider.of<SettingsViewModel>(context, listen: false)
|
context,
|
||||||
|
listen: false)
|
||||||
.continuousModeSteps);
|
.continuousModeSteps);
|
||||||
} else {
|
} else {
|
||||||
String newTaskId = await taskViewModel.createTask(message);
|
String newTaskId = await taskViewModel.createTask(message);
|
||||||
widget.viewModel.setCurrentTaskId(newTaskId);
|
widget.viewModel.setCurrentTaskId(newTaskId);
|
||||||
widget.viewModel.sendChatMessage(
|
widget.viewModel.sendChatMessage(
|
||||||
(message == "") ? null : message,
|
(message == "") ? null : message,
|
||||||
continuousModeSteps:
|
continuousModeSteps: Provider.of<SettingsViewModel>(
|
||||||
Provider.of<SettingsViewModel>(context, listen: false)
|
context,
|
||||||
|
listen: false)
|
||||||
.continuousModeSteps);
|
.continuousModeSteps);
|
||||||
}
|
}
|
||||||
|
} catch (response) {
|
||||||
|
if (response is http.Response && response.statusCode == 404) {
|
||||||
|
Fluttertoast.showToast(
|
||||||
|
msg:
|
||||||
|
"404 error: Please ensure the correct baseURL for your agent in \nthe settings and that your agent adheres to the agent protocol.",
|
||||||
|
toastLength: Toast.LENGTH_LONG,
|
||||||
|
gravity: ToastGravity.TOP,
|
||||||
|
timeInSecForIosWeb: 5,
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
webPosition: "center",
|
||||||
|
webBgColor:
|
||||||
|
"linear-gradient(to right, #dc1c13, #dc1c13)",
|
||||||
|
textColor: Colors.white,
|
||||||
|
fontSize: 16.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onContinuousModePressed: () {
|
onContinuousModePressed: () {
|
||||||
widget.viewModel.isContinuousMode =
|
widget.viewModel.isContinuousMode =
|
||||||
|
|||||||
@@ -192,6 +192,14 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
fluttertoast:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fluttertoast
|
||||||
|
sha256: "474f7d506230897a3cd28c965ec21c5328ae5605fc9c400cd330e9e9d6ac175c"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "8.2.2"
|
||||||
google_identity_services_web:
|
google_identity_services_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ dependencies:
|
|||||||
google_sign_in: ^6.1.5
|
google_sign_in: ^6.1.5
|
||||||
uuid: ^4.0.0
|
uuid: ^4.0.0
|
||||||
url_launcher: ^6.1.14
|
url_launcher: ^6.1.14
|
||||||
|
fluttertoast: ^8.2.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user