title: How do I prevent Java RetroFit from crashing my app on a 401 Unauthorized error?
body: <p>My app crashes whenever a 401 error occurs in the app.  I created a custom error handler but i'm not sure how to get the app to use this error handler so the app stops gracefully, without flashing the user "Unforunately, Application has stopped."</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    ... new RestAdapter.Builder()...setErrorHandler(getErrorHandler()).build();
  
  
  
      public ErrorHandler getErrorHandler() {
          return new ErrorHandler() {
              @Override
              public Throwable handleError(RetrofitError cause) {
                  Response r = cause.getResponse();
                  if (r != null &amp;&amp; r.getStatus() == 401) {
                      Log.e(TAG, "user not authorized:" + cause.toString());
                  } else {
                      Log.e(TAG, "regular exception thrown for CloudManager");
                  }
  
                  return cause;
              }
          };
  </code></pre>