public async Task <IApiResponseContextDto <TResponseDto> > Post(TRequestDto dto) { IApiResponseContextDto <TResponseDto> result = null; try { result = _httpHandler.Post <TRequestDto, TResponseDto>(dto); return(result); } catch (Exception e) { if (result == null) { result = new ApiResponseContextDto <TResponseDto>(); } Console.WriteLine(e); result?.Messages.Add(new MessageDto("CE1", "Unable to connect to API", MessageDtoType.Error)); //throw; return(result); } finally { if (result == null || result.HasErrors()) { _onFail?.Invoke(result); } else { _onSuccess?.Invoke(result); } _onComplete?.Invoke(result); } }
public async Task <IApiResponseContextDto <TResponseDto> > PostAsync(TRequestDto dto, string serviceDestination = "") { IApiResponseContextDto <TResponseDto> result = null; try { result = await _httpHandler.PostAsync <TRequestDto, TResponseDto>(dto, serviceDestination); return(result); } catch (Exception e) { if (result == null) { result = new ApiResponseContextDto <TResponseDto>(); } Console.WriteLine(e); result?.Messages.Add(new MessageDto("CE1", "Unable to connect to API", MessageDtoType.Error)); throw; } finally { if (result == null || result.HasErrors()) { _onFail?.Invoke(result); } else { _onSuccess?.Invoke(result); //if (_uiContext != null) { _uiContext = result.Result; } } _onComplete?.Invoke(result); } }