Skip to content

Commit 3c3fe67

Browse files
feat: Introduce StacError and StacErrorWidget for enhanced error handling (#364)
* chore: Remove unuesd StacOutlineInputBorder class from the framework UI package. * feat: Introduce StacError and StacErrorWidget for enhanced error handling - Add StacError class to encapsulate details about parsing and runtime errors, including type, original JSON, and stack trace. - Implement StacErrorWidget to display structured error information, providing context and troubleshooting tips for developers. - Update StacService to utilize StacError for error reporting and display custom error widgets when parsing fails. - Enhance error handling in JSON parsing and action execution with detailed logging and optional error widgets. * refactor: Update StacError and StacErrorWidget for improved error handling - Rename error parameter to errorDetails in StacErrorWidget for clarity. - Update documentation to reflect changes in error handling, including removal of stack trace display in the UI. - Ensure consistent usage of errorDetails across StacErrorWidget and related components.
1 parent 917e724 commit 3c3fe67

File tree

4 files changed

+724
-241
lines changed

4 files changed

+724
-241
lines changed

packages/stac/lib/src/framework/stac.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:convert';
33

44
import 'package:dio/dio.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:stac/src/framework/stac_error.dart';
67
import 'package:stac/src/framework/stac_service.dart';
78
import 'package:stac/src/services/stac_cloud.dart';
89
import 'package:stac_core/actions/network_request/stac_network_request.dart';
@@ -16,6 +17,25 @@ typedef ErrorWidgetBuilder = Widget Function(
1617

1718
typedef LoadingWidgetBuilder = Widget Function(BuildContext context);
1819

20+
/// Global parse-error widget builder for Stac.
21+
///
22+
/// Allows apps to provide a custom widget when parsing a Stac widget/action
23+
/// fails. The builder receives useful context like the widget/action type,
24+
/// original JSON and stack trace (when available).
25+
///
26+
/// Example:
27+
/// ```dart
28+
/// Stac.initialize(
29+
/// errorWidgetBuilder: (context, errorDetails) {
30+
/// return Text('Error in ${errorDetails.type}: ${errorDetails.error}');
31+
/// },
32+
/// );
33+
/// ```
34+
typedef StacErrorWidgetBuilder = Widget Function(
35+
BuildContext context,
36+
StacError errorDetails,
37+
);
38+
1939
class Stac extends StatelessWidget {
2040
const Stac({
2141
super.key,
@@ -34,13 +54,19 @@ class Stac extends StatelessWidget {
3454
List<StacActionParser> actionParsers = const [],
3555
Dio? dio,
3656
bool override = false,
57+
bool showErrorWidgets = true,
58+
bool logStackTraces = true,
59+
StacErrorWidgetBuilder? errorWidgetBuilder,
3760
}) async {
3861
return StacService.initialize(
3962
options: options,
4063
parsers: parsers,
4164
actionParsers: actionParsers,
4265
dio: dio,
4366
override: override,
67+
showErrorWidgets: showErrorWidgets,
68+
logStackTraces: logStackTraces,
69+
errorWidgetBuilder: errorWidgetBuilder,
4470
);
4571
}
4672

0 commit comments

Comments
 (0)