Search in sources :

Example 1 with ClientErrorResponse

use of com.meisolsson.githubsdk.model.ClientErrorResponse in project gh4a by slapperwan.

the class FileViewerActivity method loadFile.

private void loadFile(boolean force) {
    RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, force);
    service.getContents(mRepoOwner, mRepoName, mPath, mRef).map(ApiHelpers::throwOnFailure).map(Optional::of).onErrorResumeNext(error -> {
        if (error instanceof ApiRequestException) {
            ClientErrorResponse response = ((ApiRequestException) error).getResponse();
            List<ClientErrorResponse.FieldError> errors = response != null ? response.errors() : null;
            if (errors != null) {
                for (ClientErrorResponse.FieldError fe : errors) {
                    if (fe.reason() == ClientErrorResponse.FieldError.Reason.TooLarge) {
                        openUnsuitableFileAndFinish();
                        return Single.just(Optional.absent());
                    }
                }
            }
        }
        return Single.error(error);
    }).compose(makeLoaderSingle(ID_LOADER_FILE, force)).subscribe(result -> {
        if (result.isPresent()) {
            mContent = result.get();
            onDataReady();
            setContentEmpty(false);
        } else {
            setContentEmpty(true);
            setContentShown(true);
        }
    }, this::handleLoadFailure);
}
Also used : ApiRequestException(com.gh4a.ApiRequestException) ClientErrorResponse(com.meisolsson.githubsdk.model.ClientErrorResponse) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

ApiRequestException (com.gh4a.ApiRequestException)1 ApiHelpers (com.gh4a.utils.ApiHelpers)1 ClientErrorResponse (com.meisolsson.githubsdk.model.ClientErrorResponse)1 RepositoryContentService (com.meisolsson.githubsdk.service.repositories.RepositoryContentService)1