import 'package:fis_jsonrpc/request.dart'; import 'exception.dart'; abstract class JsonRpcInterceptor { Future onRequestTransmit(JsonRpcRequest request) async { return request; } Future> onResponse(Map response) async { return response; } Future onResponseResult(dynamic result) async { return result; } Future onResponseError(JsonRpcServerError error) async { return error; } Future onHttpRequestError( JsonRpcNetworkException error) async { return error; } } class _JsonRpcInterceptHost implements JsonRpcInterceptor { final _interceptors = []; void addInterceptor(JsonRpcInterceptor interceptor) { _interceptors.add(interceptor); } @override Future onRequestTransmit(JsonRpcRequest request) async { var pipeVal = request; for (var interceptor in _interceptors) { pipeVal = await interceptor.onRequestTransmit(pipeVal); } return pipeVal; } @override Future> onResponse(Map response) async { var pipeVal = response; for (var interceptor in _interceptors) { pipeVal = await interceptor.onResponse(pipeVal); } return pipeVal; } @override Future onResponseError(JsonRpcServerError error) async { var pipeVal = error; for (var interceptor in _interceptors) { pipeVal = await interceptor.onResponseError(pipeVal); } return pipeVal; } @override Future onHttpRequestError( JsonRpcNetworkException error) async { var pipeVal = error; for (var interceptor in _interceptors) { pipeVal = await interceptor.onHttpRequestError(pipeVal); } return pipeVal; } @override Future onResponseResult(result) async { var pipeVal = result; for (var interceptor in _interceptors) { pipeVal = await interceptor.onResponseResult(pipeVal); } return pipeVal; } } final jsonRpcInterceptHost = _JsonRpcInterceptHost();