async Task <ApiResponse <TResponse> > PostJson <TResponse>(string relativeUrl, object req) { var jsonReq = _converter.ToJson(req); _logger.Debug(this, $"Request ({req.GetType().Name}) to '{relativeUrl}': '{jsonReq}'"); var netResponse = await _network.PostJson(relativeUrl, jsonReq); ApiResponse <TResponse> result; if (netResponse.Success) { var response = _converter.FromJson <TResponse>(netResponse.Text); result = response.AsResult(); } else { var error = ConvertToError(netResponse); _errorHandle.OnError(error); result = error.AsError <TResponse>(); } _logger.Debug(this, $"Response ({typeof(TResponse).Name}) from '{relativeUrl}': {result.Success}, '{result.Result}', {result.Error}"); if (!result.Success) { OnError(result.Error); } return(result); }
protected override Task <ApiResponse <TResponse> > Post <TRequest, TResponse>(TRequest req, Func <TRequest, ApiResponse <TResponse> > handler) { try { var task = base.Post(_convert.DoubleConvert(req), handler); var resp = _convert.DoubleConvert(task.Result); if (!resp.Success) { _errorHandle.OnError(resp.Error); } return(Task.FromResult(resp)); } catch (Exception e) { _logger.Error(this, $"Post: {e}"); return(Task.FromResult(new ServerError(e.ToString()).AsError <TResponse>())); } }