Android Open Source - ElyTheme Silk Http Exception






From Project

Back to project page ElyTheme.

License

The source code is released under:

GNU General Public License

If you think the Android project ElyTheme listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.afollestad.silk.http;
//  w  w w . j  av a  2 s .c o  m
import ch.boye.httpclientandroidlib.HttpResponse;
import ch.boye.httpclientandroidlib.StatusLine;

import java.net.SocketTimeoutException;

/**
 * @author Aidan Follestad (afollestad)
 */
public class SilkHttpException extends Exception {

    private int mStatus = -1;
    private String mReason;
    private boolean mIsResponse;
    private String mResponseBody;

    SilkHttpException(String msg) {
        super(msg);
    }

    SilkHttpException(Exception e) {
        super((e instanceof SocketTimeoutException) ? "Connection timed out" : e.getMessage());
    }

    SilkHttpException(HttpResponse response, String body) {
        mIsResponse = true;
        StatusLine stat = response.getStatusLine();
        mStatus = stat.getStatusCode();
        mReason = stat.getReasonPhrase();
        mResponseBody = body;
    }

    /**
     * Gets the status code returned from the HTTP request, this will only be set if {@link #isServerResponse()} returns true.
     */
    public int getStatusCode() {
        return mStatus;
    }

    /**
     * Gets the reason phrase for the value of {@link #getStatusCode()}. this will only be set if {@link #isServerResponse()} returns true.
     */
    public String getReasonPhrase() {
        return mReason;
    }

    /**
     * Gets whether or not this exception was thrown for a non-200 HTTP response code, or if it was thrown for a code level Exception.
     */
    public boolean isServerResponse() {
        return mIsResponse;
    }

    public String getResponseBody() {
        return mResponseBody;
    }

    private final static int RESPONSE_BODY_LOG_THRESHOLD = 150;

    @Override
    public String getMessage() {
        if (isServerResponse()) {
            String message = getStatusCode() + " " + getReasonPhrase();
            if (mResponseBody != null) {
                if (mResponseBody.length() > RESPONSE_BODY_LOG_THRESHOLD)
                    message += "\n" + mResponseBody.substring(0, RESPONSE_BODY_LOG_THRESHOLD) + "\n... (response body truncated for log)";
                else message += "\n" + mResponseBody;
            }
            return message;
        }
        return super.getMessage();
    }
}




Java Source Code List

com.afollestad.cardsui.ApplicationTest.java
com.afollestad.cardsui.CardAdapter.java
com.afollestad.cardsui.CardBase.java
com.afollestad.cardsui.CardCenteredHeader.java
com.afollestad.cardsui.CardCompressed.java
com.afollestad.cardsui.CardCursorAdapter.java
com.afollestad.cardsui.CardHeader.java
com.afollestad.cardsui.CardListView.java
com.afollestad.cardsui.CardTheme.java
com.afollestad.cardsui.Card.java
com.afollestad.silk.ApplicationTest.java
com.afollestad.silk.SilkComparable.java
com.afollestad.silk.SilkCursorItem.java
com.afollestad.silk.Silk.java
com.afollestad.silk.activities.SilkDrawerActivity.java
com.afollestad.silk.adapters.ScrollStatePersister.java
com.afollestad.silk.adapters.SilkAdapter.java
com.afollestad.silk.adapters.SilkCursorAdapter.java
com.afollestad.silk.adapters.SilkSpinnerAdapter.java
com.afollestad.silk.dialogs.SilkDialog.java
com.afollestad.silk.fragments.feed.SilkCursorFeedFragment.java
com.afollestad.silk.fragments.feed.SilkFeedFragment.java
com.afollestad.silk.fragments.list.SilkCursorListFragment.java
com.afollestad.silk.fragments.list.SilkListFragment.java
com.afollestad.silk.http.SilkHttpBase.java
com.afollestad.silk.http.SilkHttpBody.java
com.afollestad.silk.http.SilkHttpCallback.java
com.afollestad.silk.http.SilkHttpClient.java
com.afollestad.silk.http.SilkHttpException.java
com.afollestad.silk.http.SilkHttpHeader.java
com.afollestad.silk.http.SilkHttpResponse.java
com.afollestad.silk.utilities.IOUtils.java
com.afollestad.silk.utilities.TimeUtils.java
com.afollestad.silk.views.ClickableToast.java
com.afollestad.silk.views.list.OnSilkScrollListener.java
com.afollestad.silk.views.list.SilkGridView.java
com.afollestad.silk.views.list.SilkListView.java
com.afollestad.silk.views.time.SilkDatePicker.java
it.gcaliendo.elytheme.Adw.java
it.gcaliendo.elytheme.ApplicationTest.java
it.gcaliendo.elytheme.DocksProvider.java
it.gcaliendo.elytheme.Docks.java
it.gcaliendo.elytheme.IconActivity.java
it.gcaliendo.elytheme.IconPack.java
it.gcaliendo.elytheme.IconsProvider.java
it.gcaliendo.elytheme.Icons.java
it.gcaliendo.elytheme.RequestActivity.java
it.gcaliendo.elytheme.ThemeActivity.java
it.gcaliendo.elytheme.Wallpaper.java
it.gcaliendo.elytheme.fragments.FragmentAbout.java
it.gcaliendo.elytheme.fragments.FragmentContact.java
it.gcaliendo.elytheme.fragments.FragmentExtras.java
it.gcaliendo.elytheme.fragments.FragmentTheme.java
it.gcaliendo.elytheme.helper.AppInfo.java
it.gcaliendo.elytheme.iconfragment.IconFragmentGames.java
it.gcaliendo.elytheme.iconfragment.IconFragmentLatest.java
it.gcaliendo.elytheme.iconfragment.IconFragmentMisc.java
it.gcaliendo.elytheme.iconfragment.IconFragmentPlay.java
it.gcaliendo.elytheme.iconfragment.IconFragmentSystem.java