示例#1
0
        static ApiResult <T> Error <T>(ApiException apiEx)
        {
            //Crashes.TrackError(apiEx);

            switch (apiEx.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                return(ApiResult.Create(default(T), false, apiEx.StatusCode, apiEx.Message));

            default:
                return(ApiResult.Create(default(T), false, apiEx.StatusCode, "Não foi possível executar a ação no servidor"));
            }
        }
示例#2
0
        public static async Task <ApiResult <bool> > Handle(this Task self, BaseViewModel vm = null)
        {
            SetBusy(vm, true);

            try {
                await self.ConfigureAwait(false);

                return(ApiResult.Create(true, true, HttpStatusCode.OK));
            } catch (ApiException ex) {
                return(Error <bool>(ex));
            } catch (Exception ex) {
                return(Error <bool>(ex));
            } finally {
                SetBusy(vm, false);
            }
        }
示例#3
0
        public static async Task <ApiResult <T> > Handle <T>(this Task <T> self, BaseViewModel vm = null)
        {
            SetBusy(vm, true);

            try {
                var result = await self.ConfigureAwait(false);

                return(ApiResult.Create(result, true, HttpStatusCode.OK));
            } catch (ApiException apiEx) {
                return(Error <T>(apiEx));
            } catch (System.Exception ex) {
                return(Error <T>(ex));
            } finally {
                SetBusy(vm, false);
            }
        }
示例#4
0
        static ApiResult <T> Error <T>(ApiException apiEx)
        {
            TrackError(apiEx);

            switch (apiEx.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                return(ApiResult.Create(default(T), false, apiEx.StatusCode, apiEx.Message));

            case HttpStatusCode.GatewayTimeout:
            case HttpStatusCode.RequestTimeout:
                return(ApiResult.Create(default(T), false, apiEx.StatusCode, "Sem Internet"));

            default:
                return(ApiResult.Create(default(T), false, apiEx.StatusCode, "Erro Servidor"));
            }
        }
示例#5
0
 static ApiResult <T> Error <T>(Exception ex)
 {
     // Crashes.TrackError(ex);
     return(ApiResult.Create(default(T), false, HttpStatusCode.ExpectationFailed, "Não foi possível executar a ação no servidor"));
 }
示例#6
0
 static ApiResult <T> Error <T>(Exception ex)
 {
     TrackError(ex);
     return(ApiResult.Create(default(T), false, HttpStatusCode.ExpectationFailed, "Erro Servidor"));
 }