예제 #1
0
        private async Task HandleHttpResponse(HttpResponseMessage response)
        {
            switch (response.StatusCode)
            {
            case System.Net.HttpStatusCode.OK:
                if (_onOK != null)
                {
                    await _onOK(response);
                }
                break;

            case System.Net.HttpStatusCode.BadRequest:
                if (_onBadRequest != null)
                {
                    await _onBadRequest(response);
                }
                break;

            case System.Net.HttpStatusCode.Unauthorized:
            case System.Net.HttpStatusCode.Forbidden:
                uriHelper.NavigateTo("/login");
                break;

            case System.Net.HttpStatusCode.InternalServerError:
                JsInterop.Toastr("error", "A server error occured, sorry");
                break;
                //other case , we do nothing, I'll add this case as needed
            }
        }
예제 #2
0
 public HttpApiClientRequestBuilder OnOK(string successMessage, string navigateTo = null)
 {
     OnOK(async() =>
     {
         if (!string.IsNullOrEmpty(successMessage))
         {
             await JsInterop.Toastr("success", successMessage);
         }
         uriHelper.NavigateTo(navigateTo);
     });
     return(this);
 }
예제 #3
0
        private async Task ExecuteHttpQuery(Func <Task <HttpResponseMessage> > httpCall)
        {
            var loaderId = JsInterop.AjaxLoaderShow(_elementRef);

            try
            {
                var response = await httpCall();
                await HandleHttpResponse(response);
            }
            catch
            {
                JsInterop.Toastr("error", "Connection error, server is down or you are not connected to the same network.");
                throw;
            }
            finally
            {
                JsInterop.AjaxLoaderHide(loaderId);
            }
        }