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 } }
private async Task SetCaptchaToken <T>(T data) { if (data is NotARobot) { (data as NotARobot).Token = await JsInterop.Captcha(this._uri); } }
/// <summary> /// returns the cookie value or null if not set /// </summary> /// <param name="cookieName"></param> /// <returns></returns> public async Task <string> Get(Func <string, bool> filterCookie) { return((await JsInterop .GetCookie()) .Split(';') .Select(v => v.TrimStart().Split('=')) .Where(s => filterCookie(s[0])) .Select(s => s[1]) .FirstOrDefault()); }
public HttpApiClientRequestBuilder OnOK(string successMessage, string navigateTo = null) { OnOK(async() => { if (!string.IsNullOrEmpty(successMessage)) { await JsInterop.Toastr("success", successMessage); } uriHelper.NavigateTo(navigateTo); }); return(this); }
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); } }