Search in sources :

Example 1 with IrregularUrlException

use of com.eros.framework.http.okhttp.exception.IrregularUrlException in project WeexErosFramework by bmfe.

the class EventFetch method parseError.

private void parseError(Context context, Exception e, JSCallback callback) {
    if (e instanceof CancelException) {
        // request canceled
        ModalManager.BmLoading.dismissLoading(context);
        return;
    }
    AxiosResultBean bean = new AxiosResultBean();
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        bean.status = httpException.getmErrorCode();
        bean.errorMsg = httpException.getmErrorMessage();
    } else if (e instanceof IrregularUrlException) {
        IrregularUrlException irregularUrlException = (IrregularUrlException) e;
        bean.status = 9;
        bean.errorMsg = irregularUrlException.getmErrosMeeage();
    } else {
        bean.status = 9;
        bean.errorMsg = e.getMessage();
    }
    if (callback != null) {
        callback.invoke(bean);
    }
}
Also used : AxiosResultBean(com.eros.framework.model.AxiosResultBean) IrregularUrlException(com.eros.framework.http.okhttp.exception.IrregularUrlException) HttpException(com.eros.framework.http.okhttp.exception.HttpException) CancelException(com.eros.framework.http.okhttp.exception.CancelException)

Example 2 with IrregularUrlException

use of com.eros.framework.http.okhttp.exception.IrregularUrlException in project WeexErosFramework by bmfe.

the class AxiosManager method delete.

public void delete(String url, String content, HashMap<String, String> header, Callback callBack, Object tag, long timeout) {
    url = safeUrl(url);
    if (url == null) {
        if (callBack != null) {
            callBack.onError(null, new IrregularUrlException("url不合法"), 0);
        }
        return;
    }
    if (header == null) {
        header = new HashMap<>();
    }
    setTimeout(timeout);
    OtherRequestBuilder builder = OkHttpUtils.delete().url(url).tag(tag).headers(header);
    if (content != null) {
        builder.requestBody(createRequestBodyByMediaType(header, content));
    }
    builder.build().execute(callBack);
}
Also used : OtherRequestBuilder(com.eros.framework.http.okhttp.builder.OtherRequestBuilder) IrregularUrlException(com.eros.framework.http.okhttp.exception.IrregularUrlException)

Example 3 with IrregularUrlException

use of com.eros.framework.http.okhttp.exception.IrregularUrlException in project WeexErosFramework by bmfe.

the class AxiosManager method get.

public void get(String mUrl, HashMap<String, String> params, HashMap<String, String> header, Callback callback, Object tag, long timeout) {
    mUrl = safeUrl(mUrl);
    if (mUrl == null) {
        if (callback != null) {
            callback.onError(null, new IrregularUrlException("url不合法"), 0);
        }
        return;
    }
    if (header == null) {
        header = new HashMap<>();
    }
    setTimeout(timeout);
    GetBuilder builder = OkHttpUtils.get().url(mUrl).tag(tag).headers(header);
    generateParams(params, builder);
    builder.build().execute(callback);
}
Also used : GetBuilder(com.eros.framework.http.okhttp.builder.GetBuilder) IrregularUrlException(com.eros.framework.http.okhttp.exception.IrregularUrlException)

Example 4 with IrregularUrlException

use of com.eros.framework.http.okhttp.exception.IrregularUrlException in project WeexErosFramework by bmfe.

the class AxiosManager method post.

public void post(String mUrl, String data, HashMap<String, String> header, Callback stringCallback, Object tag, long timeout) {
    mUrl = safeUrl(mUrl);
    if (mUrl == null) {
        if (stringCallback != null) {
            stringCallback.onError(null, new IrregularUrlException("url不合法"), 0);
        }
        return;
    }
    setTimeout(timeout);
    String contentType = null;
    if (header != null) {
        contentType = header.get("Content-Type");
    }
    if (TextUtils.isEmpty(contentType)) {
        contentType = DEFAULT_MEDIATYPE;
    }
    if (contentType.equals(DEFAULT_MEDIATYPE)) {
        OkHttpUtils.postString().url(mUrl).content(data).mediaType(MediaType.parse(contentType)).headers(header).tag(tag).build().execute(stringCallback);
    } else {
        ParseManager parseManager = ManagerFactory.getManagerService(ParseManager.class);
        HashMap params = parseManager.parseFetchParams(data);
        OkHttpUtils.post().url(mUrl).params(params).headers(header).build().execute(stringCallback);
    }
}
Also used : HashMap(java.util.HashMap) IrregularUrlException(com.eros.framework.http.okhttp.exception.IrregularUrlException)

Example 5 with IrregularUrlException

use of com.eros.framework.http.okhttp.exception.IrregularUrlException in project WeexErosFramework by bmfe.

the class AxiosManager method patch.

public void patch(String url, String content, HashMap<String, String> header, Callback callback, Object tag, long timeout) {
    url = safeUrl(url);
    if (url == null) {
        if (callback != null) {
            callback.onError(null, new IrregularUrlException("url不合法"), 0);
        }
        return;
    }
    if (header == null) {
        header = new HashMap<>();
    }
    setTimeout(timeout);
    OtherRequestBuilder builder = OkHttpUtils.patch().url(url).tag(tag).headers(header);
    if (content != null) {
        builder.requestBody(createRequestBodyByMediaType(header, content));
    }
    builder.build().execute(callback);
}
Also used : OtherRequestBuilder(com.eros.framework.http.okhttp.builder.OtherRequestBuilder) IrregularUrlException(com.eros.framework.http.okhttp.exception.IrregularUrlException)

Aggregations

IrregularUrlException (com.eros.framework.http.okhttp.exception.IrregularUrlException)7 OtherRequestBuilder (com.eros.framework.http.okhttp.builder.OtherRequestBuilder)3 GetBuilder (com.eros.framework.http.okhttp.builder.GetBuilder)1 CancelException (com.eros.framework.http.okhttp.exception.CancelException)1 HttpException (com.eros.framework.http.okhttp.exception.HttpException)1 AxiosResultBean (com.eros.framework.model.AxiosResultBean)1 HashMap (java.util.HashMap)1