renderDevErrorOverlayJson function
String
renderDevErrorOverlayJson(
- Object error,
- StackTrace stackTrace, {
- String? componentName,
- String? sourceHint,
Generates a JSON payload representation of a development error overlay.
Note: This is a development-only utility. Used by dev servers and hot-reload middleware to stream structured diagnostic payloads over WebSockets or Server-Sent Events (SSE) to connected browser clients.
Returns a JSON-encoded string with type: 'bloom-dev-error', message, stack,
and optional componentName and sourceHint.
final jsonString = renderDevErrorOverlayJson(
FormatException('Invalid JSON'),
StackTrace.current,
componentName: 'DataLoader',
);
Implementation
String renderDevErrorOverlayJson(
Object error,
StackTrace stackTrace, {
String? componentName,
String? sourceHint,
}) {
return jsonEncode({
'type': 'bloom-dev-error',
'message': error.toString(),
'stack': stackTrace.toString(),
if (componentName != null) 'componentName': componentName,
if (sourceHint != null) 'sourceHint': sourceHint,
});
}