当前位置: 首页>>代码示例>>Java>>正文


Java HttpException类代码示例

本文整理汇总了Java中com.jakewharton.retrofit2.adapter.rxjava2.HttpException的典型用法代码示例。如果您正苦于以下问题:Java HttpException类的具体用法?Java HttpException怎么用?Java HttpException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpException类属于com.jakewharton.retrofit2.adapter.rxjava2包,在下文中一共展示了HttpException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getErrorMessage

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "SocketTimeoutException";
    } else if (t instanceof IOException) {
        errorMessage = "Network Gone Down";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = cause.getLocalizedMessage();
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:22,代码来源:ApiErrorUtils.java

示例2: onError

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
@Override
public void onError(Throwable e) {
    LogUtils.e("Retrofit", e.getMessage());
    dismissProgress();
    if (e instanceof HttpException) {     //   HTTP错误
        onException(ExceptionReason.BAD_NETWORK);
    } else if (e instanceof ConnectException
            || e instanceof UnknownHostException) {   //   连接错误
        onException(CONNECT_ERROR);
    } else if (e instanceof InterruptedIOException) {   //  连接超时
        onException(CONNECT_TIMEOUT);
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {   //  解析错误
        onException(PARSE_ERROR);
    } else {
        onException(UNKNOWN_ERROR);
    }
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:20,代码来源:DefaultObserver.java

示例3: getErrorMessage

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        switch (((HttpException) t).code()){
            case 500:
                errorMessage = "Server Down Customize message";
                break;
            case 400:
                errorMessage= "Bad Request Customize Message";
                break;
            default:
                break;

        }
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "Slow Network Connection";
    } else if (t instanceof IOException) {
        errorMessage = "Network Gone Down";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = "OOPs!! Something went wrong";
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:32,代码来源:ApiErrorUtils.java

示例4: getErrorMessage

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "Internet Problem";
    } else if (t instanceof IOException) {
        errorMessage = "Internet Problem";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = "Server Bug: "+cause.getLocalizedMessage();
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:22,代码来源:ApiErrorUtils.java

示例5: getProperException

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
private Throwable getProperException(Throwable throwable)  {
    if (throwable instanceof HttpException) {
        HttpException httpException = (HttpException) throwable;
        Response response = httpException.response();
        String errorBody = null;
        try {
            String error = response.errorBody().string();
            Document htmlFile = Jsoup.parse(error, "ISO-8859-1");
            errorBody = htmlFile.body().text();
            Timber.d("response.errorBody()=%s, errorBody = %s", error, errorBody );
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (errorBody == null ) {
            return getThrowable(response.message(), response.code(), throwable);
        } else {
             return new NounResponseException(errorBody);
        }
    } else if (throwable instanceof IOException) {
        return new InternetConnectionException();
    } else if (throwable instanceof NetworkErrorException) {
        return new InternetConnectionException();
    }
    return throwable;
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:26,代码来源:ErrorHandlerHelper.java

示例6: getErrorMessage

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
public static String getErrorMessage(Throwable e, Context context, String defaultMsg) {
    if (!(e instanceof HttpException)) {
        return defaultMsg;
    }
    HttpException httpException = (HttpException) e;
    ResponseBody body = httpException.response().errorBody();
    if (body == null)
        return defaultMsg;
    try {
        String errorMessage = getErrorMessage(context, httpException, body.string());
        return errorMessage == null ? defaultMsg : errorMessage;
    } catch (IOException e1) {
        e1.printStackTrace();
        return defaultMsg;
    }
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:17,代码来源:NodeBB.java

示例7: getProperException

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
public Throwable getProperException(Throwable throwable) {
  if (throwable instanceof HttpException) {
    HttpException httpException = (HttpException) throwable;
    Response response = httpException.response();

    // try to parse the error
    Converter<ResponseBody, DataResponseModel> converter =
        retrofit.responseBodyConverter(DataResponseModel.class, new Annotation[0]);
    DataResponseModel error = null;
    try {
      error = converter.convert(response.errorBody());
    } catch (IOException | JsonSyntaxException e) {
      e.printStackTrace();
    }

    if (error == null || error.getData() == null || error.getData().getError() == null) {
      return getThrowable(response.message(), response.code(), throwable);
    } else {
      return new ParsedResponseException(error.getData().getError().get(0).getMsg());
    }
  } else if (throwable instanceof IOException) {
    return new InternetConnectionException();
  } else if (throwable instanceof NetworkErrorException) {
    return new InternetConnectionException();
  }
  return throwable;
}
 
开发者ID:nikacotAndroid,项目名称:Weather-Guru-MVP,代码行数:28,代码来源:ErrorHandlerHelper.java

示例8: getGoogleTrend_OtherHttpError

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
@Test
public void getGoogleTrend_OtherHttpError() {
    when(fancyTrendRestService.getGoogleTrend()).thenReturn(get403ForbiddenError());

    TestObserver<ArrayMap<String, List<String>>> subscriber = new TestObserver<>();
    trendRepository.getAllTrend().subscribe(subscriber);

    subscriber.awaitTerminalEvent();
    subscriber.assertError(HttpException.class);

    verify(fancyTrendRestService, times(2)).getGoogleTrend();
}
 
开发者ID:fantasy1022,项目名称:FancyTrendView,代码行数:13,代码来源:TrendRepositoryImplTest.java

示例9: login

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
public Observable<ResponseBody> login(String userName, final String password) {
    return NodeBB.getInstance()
            .getConfig()
            .flatMap(config ->
                    mRetrofit.create(UserApi.class)
                            .login(Collections.singletonMap("x-csrf-token", config.getCsrfToken()),
                                    userName, password)
                            .doOnError(error -> {
                                if (error instanceof HttpException && ((HttpException) error).code() == 403) {
                                    NodeBB.getInstance().invalidateConfig();
                                }
                            }))
            .doOnComplete(this::refreshOnlineStatus);

}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:16,代码来源:UserService.java

示例10: mapError

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
private Single<ServiceResponse> mapError(Throwable throwable) {
  if (!(throwable instanceof HttpException)) {
    return Single.error(throwable);
  }

  HttpException exception = (HttpException) throwable;
  if (exception.code() == NOT_FOUND) {
    return Single.just(new ServiceResponse(null, Collections.emptyList()));
  } else if (exception.code() == BAD_REQUEST) {
    return Single.error(new BadRequestException(exception.message(), exception));
  }
  return Single.error(throwable);
}
 
开发者ID:DiUS,项目名称:pact-workshop-android,代码行数:14,代码来源:Service.java

示例11: get403ForbiddenError

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
private Single<ArrayMap<String, List<String>>> get403ForbiddenError() {
    return Single.error(new HttpException(
            Response.error(403, ResponseBody.create(MediaType.parse("application/json"), "Forbidden"))));
}
 
开发者ID:fantasy1022,项目名称:FancyTrendView,代码行数:5,代码来源:TrendRepositoryImplTest.java

示例12: ErrorMessage

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
public static ErrorResponse ErrorMessage(Throwable e)
{
    ErrorResponse res = null;
    String errorMsg = "";
    String errorNo = "";
    Context context= Utils.getContext();
    if (context!=null)
    {
        if (e instanceof HttpException) {
            HttpException he = (HttpException) e;
            errorMsg = context.getString(R.string.api_error_connect);
            errorNo = String.valueOf(he.code());
        } else if (e instanceof UnknownHostException) {
            errorMsg = context.getString(R.string.api_error_connect);
            errorNo = e.getLocalizedMessage();
        } else if (e instanceof SocketTimeoutException) {
            errorMsg = context.getString(R.string.api_error_connect);
            errorNo = e.getLocalizedMessage();
        } else if (e instanceof ConnectException) {
            errorMsg = context.getString(R.string.api_error_connect);
            errorNo = e.getLocalizedMessage();
        } else if (e instanceof IOException) {
            errorMsg = context.getString(R.string.api_error_connect);
            errorNo = e.getLocalizedMessage();
        } else if (e instanceof IllegalStateException) {
            errorMsg = context.getString(R.string.api_error_state);
            errorNo = e.getLocalizedMessage();
        } else if (e instanceof JsonSyntaxException) {
            errorMsg = context.getString(R.string.api_error_json);
            errorNo = e.getLocalizedMessage();
        }else if (e instanceof ViewNullException) {
            errorNo = e.getLocalizedMessage();
        } else {
            errorMsg = e.getMessage();
            errorNo = e.getLocalizedMessage();
        }

    }else {
        errorNo = e.getLocalizedMessage();
    }
    if (!errorMsg.isEmpty()) {
        if (errorMsg != null) {
            res.err_msg = errorMsg;
        }
        if (errorNo != null) {
            res.err_no = errorNo;
        }
    }
    return  res;

}
 
开发者ID:CuiBow,项目名称:dagger_mvp,代码行数:52,代码来源:ApiConnect.java

示例13: handleException

import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; //导入依赖的package包/类
public static ResponeThrowable handleException(Throwable e) {
    ResponeThrowable ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ResponeThrowable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = GankApp.context().getString(R.string.network_error);
                break;
        }
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ResponeThrowable(resultException, resultException.code);
        ex.message = resultException.message;
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ResponeThrowable(e, ERROR.PARSE_ERROR);
        ex.message = GankApp.context().getString(R.string.network_error_parse);
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ResponeThrowable(e, ERROR.NETWORD_ERROR);
        ex.message = GankApp.context().getString(R.string.network_error_connect);
        return ex;
    } else if (e instanceof SSLHandshakeException) {
        ex = new ResponeThrowable(e, ERROR.SSL_ERROR);
        ex.message =  GankApp.context().getString(R.string.network_error_ssl);
        return ex;
    } else if (e instanceof ConnectTimeoutException) {
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message =  GankApp.context().getString(R.string.network_error_timeout);
        return ex;
    } else if (e instanceof SocketTimeoutException) {
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message =  GankApp.context().getString(R.string.network_error_timeout);
        return ex;
    } else {
        ex = new ResponeThrowable(e, ERROR.UNKNOWN);
        ex.message = GankApp.context().getString(R.string.network_error_unknown);
        return ex;
    }
}
 
开发者ID:dalingge,项目名称:GankGirl,代码行数:53,代码来源:HttpExceptionHandle.java


注:本文中的com.jakewharton.retrofit2.adapter.rxjava2.HttpException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。