public async Task <ProcessWorldResponse> Get([FromBody] ProcessWorldRequest request) { try { var mapped = ToClientSideMapper.Map(request); var result = await CaravanServer.ProcessWorldAsync(mapped); var response = ToDtoMapper.Map(result); return(response); } catch (ProcessRequestException e) { var result = new ProcessWorldResponse { Status = new ResponseStatus { Code = (int)e.Code, ErrorMessage = e.Message } }; _logger.LogError(e, $"Error ProcessRequestException {GetType().Name} with request='{request.ToLog()}', response='{result.ToLog()}'"); return(result); } catch (Exception e) { var result = new ProcessWorldResponse { Status = new ResponseStatus { Code = (int)ResponseStatusEnum.InernalError, ErrorMessage = e.Message } }; _logger.LogError(e, $"Error InternalServerError {GetType().Name} with request='{request.ToLog()}', response='{result.ToLog()}'"); return(result); } }
public IEnumerator ProcessWorld(IProcessWorldRequest request, Action <IProcessWorldRequest, IProcessWorldResponse> callback) { var requestBody = ToDtoMapper.Map(request); var requestString = JsonConvert.SerializeObject(requestBody); var unityWebRequest = new UnityWebRequest("http://192.168.0.101:8066/ping", "POST"); //var unityWebRequest = new UnityWebRequest("http://localhost:8066/ping", "POST"); var bodyRaw = Encoding.UTF8.GetBytes(requestString); unityWebRequest.uploadHandler = new UploadHandlerRaw(bodyRaw); unityWebRequest.downloadHandler = new DownloadHandlerBuffer(); unityWebRequest.SetRequestHeader("Content-Type", "application/json"); yield return(unityWebRequest.SendWebRequest()); if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError) { Debug.LogError($"Ping error. isNetworkError='{unityWebRequest.isNetworkError}', isHttpError='{unityWebRequest.isHttpError}', error:'{unityWebRequest.error}'"); callback(request, null); } else { var responseStr = unityWebRequest.downloadHandler.text; var response = JsonConvert.DeserializeObject <ProcessWorldResponse>(responseStr); if (response.Status == null || response.Status.Code != (int)ResponseStatusEnum.Success) { Debug.LogError($"Ping error. response code='{response.Status?.Code}', error='{response.Status?.ErrorMessage}'"); } else { Debug.Log("Ping ok'"); var result = ToClientSideMapper.Map(response); callback(request, result); } } }