Codota Logo
HttpException.code
Code IndexAdd Codota to your IDE (free)

How to use
code
method
in
retrofit2.HttpException

Best Java code snippets using retrofit2.HttpException.code (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: JessYanCoding/ArmsComponent

  private String convertStatusCode(HttpException httpException) {
    String msg;
    if (httpException.code() == 500) {
      msg = "服务器发生错误";
    } else if (httpException.code() == 404) {
      msg = "请求地址不存在";
    } else if (httpException.code() == 403) {
      msg = "请求被服务器拒绝";
    } else if (httpException.code() == 401) {
      msg = "未授权";
    } else if (httpException.code() == 307) {
      msg = "请求被重定向到其他页面";
    } else {
      msg = httpException.message();
    }
    return msg;
  }
}
origin: GrossumUA/TAS_Android_Boilerplate

/**
 * Returns true if the Throwable is an instance of RetrofitError with an
 * http status code equals to the given one.
 */
public static boolean isHttpStatusCode(Throwable throwable, int statusCode) {
  return throwable instanceof HttpException
    && ((HttpException) throwable).code() == statusCode;
}
origin: noterpopo/Hands-Chopping

  private String convertStatusCode(HttpException httpException) {
    String msg;
    if (httpException.code() == 500) {
      msg = "服务器发生错误";
    } else if (httpException.code() == 404) {
      msg = "请求地址不存在";
    } else if (httpException.code() == 403) {
      msg = "请求被服务器拒绝";
    } else if (httpException.code() == 307) {
      msg = "请求被重定向到其他页面";
    } else {
      msg = httpException.message();
    }
    return msg;
  }
}
origin: ragdroid/mockstar

  @Override
  public void accept(@NonNull Throwable throwable) throws Exception {
    if (throwable instanceof HttpException) {
      if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) {
        if (getScene() != null) {
          getScene().showErrorDialog("Lost!");
        }
      } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) {
        if (getScene() != null) {
          getScene().showErrorDialog("Fire on the Server");
        }
      } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
        if (getScene() != null) {
          getScene().showErrorDialog("You shall not pass!");
        }
      }
    } else {
      if (getScene() != null) {
        getScene().showErrorDialog(throwable.getMessage());
      }
    }
    throwable.printStackTrace();
  }
});
origin: abbas-oveissi/SearchMovies

@Override
public void onError(Throwable e) {
  if (e instanceof HttpException) {
    viewLayer.showError("StatusCode: " + ((HttpException) e).code());
  } else if (e instanceof GeneralApiException) {
    viewLayer.showError(((GeneralApiException) e).message);
  } else {
    viewLayer.showError(e.getMessage());
  }
}
origin: abbas-oveissi/SearchMovies

@Override
public void onError(Throwable e) {
  if (e instanceof HttpException) {
    viewLayer.showError("StatusCode: " + ((HttpException) e).code());
  } else if (e instanceof GeneralApiException) {
    viewLayer.showError(((GeneralApiException) e).message);
  } else {
    viewLayer.showError(e.getMessage());
  }
}
origin: 0xZhangKe/ShiZhong

@Override
public void onError(Throwable e) {
  String errorMessage;
  if (e instanceof HttpException) {
    errorMessage = SZApplication.getInstance().getResources().getString(R.string.network_error);
    String detail = getErrorDetail((HttpException) e);
    if (!TextUtils.isEmpty(detail)) {
      errorMessage = detail;
    }
    Log.e(TAG, "网络错误,code:" + ((HttpException) e).code(), e);
  } else if (e instanceof SocketTimeoutException) {
    errorMessage = SZApplication.getInstance().getResources().getString(R.string.time_out_error);
    Log.e(TAG, "连接超时", e);
  } else if (e instanceof ConnectException) {
    errorMessage = SZApplication.getInstance().getResources().getString(R.string.network_error);
    Log.e(TAG, "网络错误", e);
  } else if (e instanceof JsonParseException
      || e instanceof JSONException
      || e instanceof ParseException) {
    errorMessage = SZApplication.getInstance().getResources().getString(R.string.data_error);
    Log.e(TAG, "数据错误", e);
  } else {
    errorMessage = SZApplication.getInstance().getResources().getString(R.string.network_error);
    Log.e(TAG, "网络错误", e);
  }
  onErrorResponse(errorMessage);
}
origin: ragdroid/mockstar

@Test
public void testDemoResponseError401() {
  reset(mainSceneMock);
  MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);
  when(httpException.code()).thenReturn(HttpURLConnection.HTTP_UNAUTHORIZED);
  when(pokeDataSource.getPokemonAbilityStringObservable(anyString()))
      .thenReturn(Observable.<String>error(httpException));
  presenter.onSceneAdded(mainSceneMock, null);
  testScheduler.triggerActions();
  verify(mainSceneMock, times(1)).showErrorDialog("You shall not pass!");
  verify(mainSceneMock, times(0)).setApiText(anyString());
}
origin: ragdroid/mockstar

@Test
public void testDemoResponseError404() {
  reset(mainSceneMock);
  MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);
  when(httpException.code()).thenReturn(HttpURLConnection.HTTP_NOT_FOUND);
  when(pokeDataSource.getPokemonAbilityStringObservable(anyString()))
      .thenReturn(Observable.<String>error(httpException));
  presenter.onSceneAdded(mainSceneMock, null);
  testScheduler.triggerActions();
  verify(mainSceneMock, times(1)).showErrorDialog("Lost!");
  verify(mainSceneMock, times(0)).setApiText(anyString());
}
origin: ragdroid/mockstar

@Test
public void testDemoResponseError503() {
  reset(mainSceneMock);
  MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);
  when(httpException.code()).thenReturn(HttpURLConnection.HTTP_UNAVAILABLE);
  when(pokeDataSource.getPokemonAbilityStringObservable(anyString()))
      .thenReturn(Observable.<String>error(httpException));
  presenter.onSceneAdded(mainSceneMock, null);
  testScheduler.triggerActions();
  verify(mainSceneMock, times(0)).setApiText(anyString());
  verify(mainSceneMock, times(1)).showErrorDialog("Fire on the Server");
}
origin: bigeyechou/Rxjava2Retrofit2NetFrame

int code = ((HttpException) e).code();
if (code == 504) {
origin: jruesga/rview

@SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ConstantConditions", "deprecation"})
private static boolean isHttpException(Throwable cause, int httpCode) {
  if (isException(cause, retrofit2.HttpException.class)) {
    retrofit2.HttpException httpException =
        (retrofit2.HttpException)
            getCause(cause, retrofit2.HttpException.class);
    return httpCode == httpException.code();
  }
  if (isException(cause, retrofit2.adapter.rxjava2.HttpException.class)) {
    retrofit2.adapter.rxjava2.HttpException httpException =
        (retrofit2.adapter.rxjava2.HttpException)
            getCause(cause, retrofit2.adapter.rxjava2.HttpException.class);
    return httpCode == httpException.code();
  }
  return false;
}
origin: jruesga/rview

@SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ConstantConditions", "deprecation"})
private static boolean isHttpException(Throwable cause, int httpCode) {
  if (isException(cause, retrofit2.HttpException.class)) {
    retrofit2.HttpException httpException =
        (retrofit2.HttpException)
            getCause(cause, retrofit2.HttpException.class);
    return httpCode == httpException.code();
  }
  if (isException(cause, retrofit2.adapter.rxjava2.HttpException.class)) {
    retrofit2.adapter.rxjava2.HttpException httpException =
        (retrofit2.adapter.rxjava2.HttpException)
            getCause(cause, retrofit2.adapter.rxjava2.HttpException.class);
    return httpCode == httpException.code();
  }
  return false;
}
origin: playerone-id/EosCommander

@Override
public void onError(Throwable e) {
  MvpPresenter<? extends MvpView> presenter = mPresenterRef.get();
  if ( (null == presenter ) || ! presenter.isViewAttached()) {
    return;
  }
  presenter.getMvpView().showLoading( false );
  if (e instanceof HttpException) {
    ResponseBody responseBody = ((HttpException) e).response().errorBody();
    presenter.getMvpView().onError( String.format( "HttpCode:%d\n\n%s", ((HttpException) e).code(), getErrorMessage(responseBody)));
  } else if (e instanceof SocketTimeoutException) {
    presenter.getMvpView().onError(R.string.timeout);
  } else if (e instanceof IOException) {
    presenter.getMvpView().onError(R.string.network_err);
  } else {
    e.printStackTrace();
    presenter.getMvpView().onError(e.getMessage());
  }
}
origin: playerone-id/EosCommander

protected void notifyErrorToMvpView( Throwable e){
  getMvpView().showLoading(false);
  if (e instanceof HttpException) {
    ResponseBody responseBody = ((HttpException) e).response().errorBody();
    getMvpView().onError( String.format( "HttpCode:%d\n\n%s", ((HttpException) e).code(), getErrorMessage(responseBody)));
  } else if (e instanceof SocketTimeoutException) {
    getMvpView().onError(R.string.timeout);
  } else if (e instanceof IOException) {
    getMvpView().onError(R.string.network_err);
  } else {
    getMvpView().onError(e.getMessage());
  }
}
origin: majunm/HttpX

ex = new ApiException(e, ApiCode.Request.HTTP_ERROR);
switch (httpException.code()) {
  case ApiCode.Http.INTERNAL_SERVER_ERROR:
    ex.message = "服务器内部错误,错误码:" + ApiCode.Http.INTERNAL_SERVER_ERROR;
origin: woxingxiao/GracefulMovies

} else if (e instanceof HttpException) {
  HttpException httpException = (HttpException) e;
  switch (httpException.code()) {
    case HTTP_BAD_REQUEST:
    case HTTP_FORBIDDEN:
origin: jruesga/rview

    (retrofit2.HttpException)
        getCause(cause, retrofit2.HttpException.class);
message = httpCode2MessageResource(httpException.code());
origin: lygttpod/RxHttpUtils

if (e instanceof HttpException) {
  HttpException httpException = (HttpException) e;
  ex = new ApiException(httpException, httpException.code());
  ex.message = httpException.getMessage();
} else if (e instanceof SocketTimeoutException) {
origin: RuffianZhong/Rx-Mvp

if (e instanceof HttpException) {             //HTTP错误
  HttpException httpExc = (HttpException) e;
  ex = new ApiException(e, httpExc.code());
  ex.setMsg("网络错误");  //均视为网络错误
  return ex;
retrofit2HttpExceptioncode

Javadoc

HTTP status code.

Popular methods of HttpException

  • response
    The full HTTP response. This may be null if the exception was serialized.
  • <init>
  • getMessage
  • message
    HTTP status message.

Popular in Java

  • Start an intent from android
  • getSystemService (Context)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Pattern (java.util.regex)
    A compiled representation of a regular expression. A regular expression, specified as a string, must
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Runner (org.openjdk.jmh.runner)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now