handle method
Handles a single decoded request map and returns the response envelope.
Never throws for a RepoException; unexpected errors surface as a generic
RepoException-typed error so a server can always reply with valid JSON.
Implementation
Future<Map<String, Object?>> handle(Map<String, Object?> request) async {
final op = request['op'];
if (op is! String) {
return _err('RepoException', "Missing or invalid 'op' field.");
}
try {
final result = await _dispatch(op, request);
return <String, Object?>{'ok': true, 'result': result};
} on RepoPermissionException catch (e) {
return _err('RepoPermissionException', e.message);
} on RepoException catch (e) {
return _err('RepoException', e.message);
} catch (e) {
return _err('RepoException', e.toString());
}
}