com.androidnetworking.error.ANError Java Examples

The following examples show how to use com.androidnetworking.error.ANError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From RxJava2-Android-Samples with Apache License 2.0 6 votes vote down vote up
public static void logError(String TAG, Throwable e) {
    if (e instanceof ANError) {
        ANError anError = (ANError) e;
        if (anError.getErrorCode() != 0) {
            // received ANError from server
            // error.getErrorCode() - the ANError code from server
            // error.getErrorBody() - the ANError body from server
            // error.getErrorDetail() - just a ANError detail
            Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
            Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
            Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
        } else {
            // error.getErrorDetail() : connectionError, parseError, requestCancelledError
            Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
        }
    } else {
        Log.d(TAG, "onError errorMessage : " + e.getMessage());
    }
}
 
Example #2
Source File: DataManager.java    From Android-MVP-Sample-Application with Apache License 2.0 6 votes vote down vote up
public void getData(final DataListener listener) {

        final String data = mPreferencesHelper.getData();

        if (data != null) {
            listener.onResponse(data);
            return;
        }

        mApiHelper.getData(new StringRequestListener() {
            @Override
            public void onResponse(String response) {
                mPreferencesHelper.putData(response);
                listener.onResponse(response);
            }

            @Override
            public void onError(ANError anError) {
                listener.onError(anError.getErrorDetail());
            }
        });

    }
 
Example #3
Source File: MainPresenter.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawerOptionLogoutClick() {
    getMvpView().showLoading();

    getCompositeDisposable().add(getDataManager().doLogoutApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<LogoutResponse>() {
                @Override
                public void accept(LogoutResponse response) throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getDataManager().setUserAsLoggedOut();
                    getMvpView().hideLoading();
                    getMvpView().openLoginActivity();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));

}
 
Example #4
Source File: OpenSourcePresenter.java    From android-mvp-interactor-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getInteractor()
            .getOpenSourceApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<OpenSourceResponse>() {
                @Override
                public void accept(@NonNull OpenSourceResponse openSourceResponse)
                        throws Exception {
                    if (openSourceResponse != null && openSourceResponse.getData() != null) {
                        getMvpView().updateRepo(openSourceResponse.getData());
                    }
                    getMvpView().hideLoading();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable)
                        throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #5
Source File: BlogPresenter.java    From android-mvp-interactor-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getInteractor()
            .getBlogApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<BlogResponse>() {
                @Override
                public void accept(@NonNull BlogResponse blogResponse)
                        throws Exception {
                    if (blogResponse != null && blogResponse.getData() != null) {
                        getMvpView().updateBlog(blogResponse.getData());
                    }
                    getMvpView().hideLoading();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable)
                        throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #6
Source File: BlogPresenter.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getDataManager()
            .getBlogApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<BlogResponse>() {
                @Override
                public void accept(@NonNull BlogResponse blogResponse)
                        throws Exception {
                    if (blogResponse != null && blogResponse.getData() != null) {
                        getMvpView().updateBlog(blogResponse.getData());
                    }
                    getMvpView().hideLoading();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable)
                        throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #7
Source File: MainPresenter.java    From android-mvp-interactor-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawerOptionLogoutClick() {
    getMvpView().showLoading();

    getCompositeDisposable().add(getInteractor().doLogoutApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<LogoutResponse>() {
                @Override
                public void accept(LogoutResponse response) throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getInteractor().setUserAsLoggedOut();
                    getMvpView().hideLoading();
                    getMvpView().openLoginActivity();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));

}
 
Example #8
Source File: OpenSourcePresenter.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getDataManager()
            .getOpenSourceApiCall()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<OpenSourceResponse>() {
                @Override
                public void accept(@NonNull OpenSourceResponse openSourceResponse)
                        throws Exception {
                    if (openSourceResponse != null && openSourceResponse.getData() != null) {
                        getMvpView().updateRepo(openSourceResponse.getData());
                    }
                    getMvpView().hideLoading();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable)
                        throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #9
Source File: DJILogger.java    From Android-Bridge-App with MIT License 5 votes vote down vote up
@Override
public void run() {

    while (isNetworkEnabled) {
        if (messageQueue.size() > 0) {
            final JSONObject object = messageQueue.remove(0);
            AndroidNetworking.post(serverURL).addBodyParameter("data", object.toString()).build()
                    .getAsOkHttpResponse(new OkHttpResponseListener() {
                        @Override
                        public void onResponse(Response response) {
                            //DO Nothing
                        }

                        @Override
                        public void onError(ANError anError) {
                            Log.e(TAG, "Error: " + anError);
                        }
                    });
        }
    }
}
 
Example #10
Source File: Muvix.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onComplete){
    AndroidNetworking.get(fixURL(url))
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parse(response);
                    if (xModels!=null){
                        onComplete.onTaskCompleted(xModels,true);
                    }else onComplete.onError();
                }

                @Override
                public void onError(ANError anError) {
                    onComplete.onError();
                }
            });
}
 
Example #11
Source File: Vlare.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parseVideo(response);
                    if (xModels.isEmpty()){
                        onTaskCompleted.onError();
                    }else onTaskCompleted.onTaskCompleted(Utils.sortMe(xModels), true);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #12
Source File: BitTube.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    String id = getBitTubeID(url);
    if (id!=null) {
        AndroidNetworking.get("https://bittube.video/api/v1/videos/" + id)
                .build()
                .getAsString(new StringRequestListener() {
                    @Override
                    public void onResponse(String response) {
                        ArrayList<XModel> xModels = parseVideo(response);
                        if (xModels.isEmpty()) {
                            onTaskCompleted.onError();
                        } else onTaskCompleted.onTaskCompleted(Utils.sortMe(xModels), true);
                    }

                    @Override
                    public void onError(ANError anError) {
                        onTaskCompleted.onError();
                    }
                });
    }else onTaskCompleted.onError();
}
 
Example #13
Source File: GPhotos.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .setUserAgent(LowCostVideo.agent)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = GPhotosUtils.getGPhotoLink(response);
                    onTaskCompleted.onTaskCompleted(xModels,true);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #14
Source File: VideoBIN.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parseVideo(response);
                    if (xModels.isEmpty()) {
                        onTaskCompleted.onError();
                    } else onTaskCompleted.onTaskCompleted(Utils.sortMe(xModels), true);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #15
Source File: SendVid.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    String src = getSrc(response);
                    if (src!=null){
                        ArrayList<XModel> xModels = new ArrayList<>();
                        putModel(src,"Normal",xModels);
                        onTaskCompleted.onTaskCompleted(xModels,false);
                    }else onTaskCompleted.onError();
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #16
Source File: Vudeo.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parseVideo(response);
                    if (xModels.isEmpty()){
                        onTaskCompleted.onError();
                    }else onTaskCompleted.onTaskCompleted(xModels, false);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #17
Source File: MFire.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(fixURL(url))
            .addHeaders("User-agent", agent)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    final String regex = "aria-label=\"Download file\"\\n.+href=\"(.*)\"";
                    final Pattern pattern = Pattern.compile(regex);
                    final Matcher matcher = pattern.matcher(response);
                    if (matcher.find()) {
                        ArrayList<XModel> xModels = new ArrayList<>();
                        putModel(matcher.group(1),"Normal",xModels);
                        onTaskCompleted.onTaskCompleted(xModels,false);
                    }else onTaskCompleted.onError();
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #18
Source File: FEmbed.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onComplete){
    String id = get_fEmbed_video_ID(url);
    if (id!=null){
        AndroidNetworking.post("https://www.fembed.com/api/source/"+id)
                .build()
                .getAsString(new StringRequestListener() {
                    @Override
                    public void onResponse(String response) {
                        ArrayList<XModel> xModels = parse(response);
                        if (xModels!=null){
                            onComplete.onTaskCompleted(sortMe(xModels),true);
                        }else onComplete.onError();
                    }

                    @Override
                    public void onError(ANError anError) {
                        onComplete.onError();
                    }
                });
    }else onComplete.onError();
}
 
Example #19
Source File: StreamTape.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parseVideo(response);
                    if (xModels.isEmpty()){
                        onTaskCompleted.onError();
                    }else onTaskCompleted.onTaskCompleted(xModels, false);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #20
Source File: TW.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onComplete){
    AndroidNetworking.post("https://twdown.net/download.php")
            .addBodyParameter("URL", url)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    onComplete.onTaskCompleted(sortMe(Twitter.fetch(response)),true);
                }

                @Override
                public void onError(ANError anError) {
                    onComplete.onError();
                }
            });
}
 
Example #21
Source File: SolidFiles.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onComplete){
    AndroidNetworking.get(url)
            .addHeaders("User-Agent","Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Safari/537.36")
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parse(response);
                    if (xModels!=null){
                        onComplete.onTaskCompleted(xModels,false);
                    }else onComplete.onError();
                }

                @Override
                public void onError(ANError anError) {
                    onComplete.onError();
                }
            });
}
 
Example #22
Source File: GoUnlimited.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onComplete){
    AndroidNetworking.get(url)
            .setUserAgent(agent)
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parse(response);
                    if (xModels!=null){
                        onComplete.onTaskCompleted(xModels,false);
                    }else onComplete.onError();
                }

                @Override
                public void onError(ANError anError) {
                    onComplete.onError();
                }
            });
}
 
Example #23
Source File: MP4Upload.java    From xGetter with Apache License 2.0 5 votes vote down vote up
public static void fetch(String url, final LowCostVideo.OnTaskCompleted onTaskCompleted){
    AndroidNetworking.get(fixURL(url))
            .build()
            .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    ArrayList<XModel> xModels = parseVideo(response);
                    if (xModels==null){
                        onTaskCompleted.onError();
                    }else onTaskCompleted.onTaskCompleted(xModels, false);
                }

                @Override
                public void onError(ANError anError) {
                    onTaskCompleted.onError();
                }
            });
}
 
Example #24
Source File: BridgeUpdateService.java    From Android-Bridge-App with MIT License 4 votes vote down vote up
@Override
public void run() {
    AndroidNetworking.post(VERSION_CHECK_URL).build().getAsString(new StringRequestListener() {
        @Override
        public void onResponse(String response) {

            try {
                JSONObject jsonObject = new JSONObject(response);
                if (jsonObject != null) {
                    String versionName = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0).versionName;
                    if (versionName != null) {
                        if (Utils.compareVersionNames(versionName, jsonObject.getString("version")) == -1) {
                            Runtime.getRuntime().exec("dpm set-device-owner com.dji.wsbridge/.DeviceAdminRcvr");
                            updateApp();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        @Override
        public void onError(ANError anError) {
            Log.d("BridgeUpdateService", "error " + anError.getErrorCode() + anError.getErrorDetail());

        }

    });

}
 
Example #25
Source File: BaseActivity.java    From EasyVPN-Free with GNU General Public License v3.0 4 votes vote down vote up
protected void getIpInfo(final List<Server> serverList) {
    JSONArray jsonArray = new JSONArray();

    for (Server server : serverList) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("query", server.getIp());
            jsonObject.put("lang", Locale.getDefault().getLanguage());

            jsonArray.put(jsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    AndroidNetworking.post(getString(R.string.url_check_ip_batch))
            .addJSONArrayBody(jsonArray)
            .setTag("getIpInfo")
            .setPriority(Priority.MEDIUM)
            .build()
            .getAsJSONArray(new JSONArrayRequestListener() {
                @Override
                public void onResponse(JSONArray response) {
                    if (dbHelper.setIpInfo(response, serverList))
                        ipInfoResult();
                }
                @Override
                public void onError(ANError error) {

                }
            });
}
 
Example #26
Source File: LoginPresenter.java    From android-mvp-architecture with Apache License 2.0 4 votes vote down vote up
@Override
public void onFacebookLoginClick() {
    // instruct LoginActivity to initiate facebook login
    getMvpView().showLoading();

    getCompositeDisposable().add(getDataManager()
            .doFacebookLoginApiCall(new LoginRequest.FacebookLoginRequest("test3", "test4"))
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<LoginResponse>() {
                @Override
                public void accept(LoginResponse response) throws Exception {
                    getDataManager().updateUserInfo(
                            response.getAccessToken(),
                            response.getUserId(),
                            DataManager.LoggedInMode.LOGGED_IN_MODE_FB,
                            response.getUserName(),
                            response.getUserEmail(),
                            response.getGoogleProfilePicUrl());

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();
                    getMvpView().openMainActivity();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #27
Source File: LoginPresenter.java    From android-mvp-architecture with Apache License 2.0 4 votes vote down vote up
@Override
public void onGoogleLoginClick() {
    // instruct LoginActivity to initiate google login
    getMvpView().showLoading();

    getCompositeDisposable().add(getDataManager()
            .doGoogleLoginApiCall(new LoginRequest.GoogleLoginRequest("test1", "test1"))
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<LoginResponse>() {
                @Override
                public void accept(LoginResponse response) throws Exception {
                    getDataManager().updateUserInfo(
                            response.getAccessToken(),
                            response.getUserId(),
                            DataManager.LoggedInMode.LOGGED_IN_MODE_GOOGLE,
                            response.getUserName(),
                            response.getUserEmail(),
                            response.getGoogleProfilePicUrl());

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();
                    getMvpView().openMainActivity();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #28
Source File: LoginPresenter.java    From android-mvp-architecture with Apache License 2.0 4 votes vote down vote up
@Override
public void onServerLoginClick(String email, String password) {
    //validate email and password
    if (email == null || email.isEmpty()) {
        getMvpView().onError(R.string.empty_email);
        return;
    }
    if (!CommonUtils.isEmailValid(email)) {
        getMvpView().onError(R.string.invalid_email);
        return;
    }
    if (password == null || password.isEmpty()) {
        getMvpView().onError(R.string.empty_password);
        return;
    }
    getMvpView().showLoading();

    getCompositeDisposable().add(getDataManager()
            .doServerLoginApiCall(new LoginRequest.ServerLoginRequest(email, password))
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<LoginResponse>() {
                @Override
                public void accept(LoginResponse response) throws Exception {
                    getDataManager().updateUserInfo(
                            response.getAccessToken(),
                            response.getUserId(),
                            DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER,
                            response.getUserName(),
                            response.getUserEmail(),
                            response.getGoogleProfilePicUrl());

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();
                    getMvpView().openMainActivity();

                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}
 
Example #29
Source File: BasePresenter.java    From android-mvp-interactor-architecture with Apache License 2.0 4 votes vote down vote up
@Override
public void handleApiError(ANError error) {

    if (error == null || error.getErrorBody() == null) {
        getMvpView().onError(R.string.api_default_error);
        return;
    }

    if (error.getErrorCode() == AppConstants.API_STATUS_CODE_LOCAL_ERROR
            && error.getErrorDetail().equals(ANConstants.CONNECTION_ERROR)) {
        getMvpView().onError(R.string.connection_error);
        return;
    }

    if (error.getErrorCode() == AppConstants.API_STATUS_CODE_LOCAL_ERROR
            && error.getErrorDetail().equals(ANConstants.REQUEST_CANCELLED_ERROR)) {
        getMvpView().onError(R.string.api_retry_error);
        return;
    }

    final GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
    final Gson gson = builder.create();

    try {
        ApiError apiError = gson.fromJson(error.getErrorBody(), ApiError.class);

        if (apiError == null || apiError.getMessage() == null) {
            getMvpView().onError(R.string.api_default_error);
            return;
        }

        switch (error.getErrorCode()) {
            case HttpsURLConnection.HTTP_UNAUTHORIZED:
            case HttpsURLConnection.HTTP_FORBIDDEN:
                setUserAsLoggedOut();
                getMvpView().openActivityOnTokenExpire();
            case HttpsURLConnection.HTTP_INTERNAL_ERROR:
            case HttpsURLConnection.HTTP_NOT_FOUND:
            default:
                getMvpView().onError(apiError.getMessage());
        }
    } catch (JsonSyntaxException | NullPointerException e) {
        Log.e(TAG, "handleApiError", e);
        getMvpView().onError(R.string.api_default_error);
    }
}
 
Example #30
Source File: BasePresenter.java    From android-mvp-architecture with Apache License 2.0 4 votes vote down vote up
@Override
public void handleApiError(ANError error) {

    if (error == null || error.getErrorBody() == null) {
        getMvpView().onError(R.string.api_default_error);
        return;
    }

    if (error.getErrorCode() == AppConstants.API_STATUS_CODE_LOCAL_ERROR
            && error.getErrorDetail().equals(ANConstants.CONNECTION_ERROR)) {
        getMvpView().onError(R.string.connection_error);
        return;
    }

    if (error.getErrorCode() == AppConstants.API_STATUS_CODE_LOCAL_ERROR
            && error.getErrorDetail().equals(ANConstants.REQUEST_CANCELLED_ERROR)) {
        getMvpView().onError(R.string.api_retry_error);
        return;
    }

    final GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
    final Gson gson = builder.create();

    try {
        ApiError apiError = gson.fromJson(error.getErrorBody(), ApiError.class);

        if (apiError == null || apiError.getMessage() == null) {
            getMvpView().onError(R.string.api_default_error);
            return;
        }

        switch (error.getErrorCode()) {
            case HttpsURLConnection.HTTP_UNAUTHORIZED:
            case HttpsURLConnection.HTTP_FORBIDDEN:
                setUserAsLoggedOut();
                getMvpView().openActivityOnTokenExpire();
            case HttpsURLConnection.HTTP_INTERNAL_ERROR:
            case HttpsURLConnection.HTTP_NOT_FOUND:
            default:
                getMvpView().onError(apiError.getMessage());
        }
    } catch (JsonSyntaxException | NullPointerException e) {
        Log.e(TAG, "handleApiError", e);
        getMvpView().onError(R.string.api_default_error);
    }
}