Search in sources :

Example 1 with NoHAtHClientException

use of com.hippo.ehviewer.client.exception.NoHAtHClientException in project EhViewer by seven332.

the class EhEngine method downloadArchive.

public static Void downloadArchive(@Nullable EhClient.Task task, OkHttpClient okHttpClient, long gid, String token, String or, String res) throws Exception {
    if (or == null || or.length() == 0) {
        throw new EhException("Invalid form param or: " + or);
    }
    if (res == null || res.length() == 0) {
        throw new EhException("Invalid res: " + res);
    }
    FormBody.Builder builder = new FormBody.Builder();
    builder.add("hathdl_xres", res);
    String url = EhUrl.getDownloadArchive(gid, token, or);
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        throwException(call, code, headers, body, null);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    Matcher m = PATTERN_NEED_HATH_CLIENT.matcher(body);
    if (m.find()) {
        throw new NoHAtHClientException("No H@H client");
    }
    return null;
}
Also used : Call(okhttp3.Call) Matcher(java.util.regex.Matcher) Headers(okhttp3.Headers) FormBody(okhttp3.FormBody) Request(okhttp3.Request) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException) EhException(com.hippo.ehviewer.client.exception.EhException) Response(okhttp3.Response)

Aggregations

CancelledException (com.hippo.ehviewer.client.exception.CancelledException)1 EhException (com.hippo.ehviewer.client.exception.EhException)1 NoHAtHClientException (com.hippo.ehviewer.client.exception.NoHAtHClientException)1 ParseException (com.hippo.ehviewer.client.exception.ParseException)1 StatusCodeException (com.hippo.network.StatusCodeException)1 Matcher (java.util.regex.Matcher)1 Call (okhttp3.Call)1 FormBody (okhttp3.FormBody)1 Headers (okhttp3.Headers)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1