load method
FR-APP-ONLINE-001~004 — Raw JSON form used internally by loadOnline and by legacy callers.
Implementation
Future<Map<String, dynamic>> load(Client client) async {
final List<Resource> resources;
try {
resources = await client.listResources();
} catch (e, st) {
throw _wrapLoad('listResources failed', e, st);
}
_logger.debug('Resources listed', {'count': resources.length});
final appUri = _pickAppUri(resources);
if (appUri == null) {
throw ResourceNotFoundException('No UI resources found');
}
_logger.info('Loading application', {'uri': appUri});
final ReadResourceResult resource;
try {
resource = await client.readResource(appUri);
} catch (e, st) {
throw _wrapLoad('readResource failed', e, st);
}
if (resource.contents.isEmpty) {
throw DefinitionParseException(appUri);
}
final text = resource.contents.first.text;
if (text == null) {
throw DefinitionParseException(appUri);
}
try {
final decoded = jsonDecode(text);
if (decoded is! Map<String, dynamic>) {
throw DefinitionParseException(appUri);
}
return decoded;
} on DefinitionParseException {
rethrow;
} catch (e) {
throw DefinitionParseException(appUri, cause: e);
}
}