Search in sources :

Example 1 with MwServiceError

use of org.wikipedia.dataclient.mwapi.MwServiceError in project apps-android-wikipedia by wikimedia.

the class DescriptionEditClient method handleError.

private void handleError(@NonNull Call<DescriptionEdit> call, @NonNull DescriptionEdit body, @NonNull Callback cb) {
    MwServiceError error = body.getError();
    String info = body.info();
    RuntimeException exception = new RuntimeException(info != null ? info : "An unknown error occurred");
    if (body.badLoginState() || body.badToken()) {
        cb.invalidLogin(call, exception);
    } else if (error != null && error.hasMessageName(ABUSEFILTER_DISALLOWED)) {
        cb.abusefilter(call, ABUSEFILTER_DISALLOWED, error.getMessageHtml(ABUSEFILTER_DISALLOWED));
    } else if (error != null && error.hasMessageName(ABUSEFILTER_WARNING)) {
        cb.abusefilter(call, ABUSEFILTER_WARNING, error.getMessageHtml(ABUSEFILTER_WARNING));
    } else {
        // noinspection ConstantConditions
        cb.failure(call, new MwException(error));
    }
}
Also used : MwException(org.wikipedia.dataclient.mwapi.MwException) MwServiceError(org.wikipedia.dataclient.mwapi.MwServiceError)

Example 2 with MwServiceError

use of org.wikipedia.dataclient.mwapi.MwServiceError in project apps-android-wikipedia by wikimedia.

the class BasePageLeadTest method verifyError.

protected void verifyError(MwMobileViewPageLead pageLead, MwMobileViewPageLead.Mobileview mv) {
    assertThat(mv, equalTo(null));
    MwServiceError error = pageLead.getError();
    assertThat(pageLead.hasError(), is(true));
    assert error != null;
    assertThat(error.getTitle(), is("nopage"));
    assertThat(error.getDetails(), is("The page parameter must be set"));
    assertThat(error.getDocRef(), is("See https://en.wikipedia.org/w/api.php for API usage"));
}
Also used : MwServiceError(org.wikipedia.dataclient.mwapi.MwServiceError)

Example 3 with MwServiceError

use of org.wikipedia.dataclient.mwapi.MwServiceError in project apps-android-wikipedia by wikimedia.

the class PageFragmentLoadState method pageLoadLeadSectionComplete.

private void pageLoadLeadSectionComplete(PageLead pageLead, int startSequenceNum) {
    if (!fragment.isAdded() || !sequenceNumber.inSync(startSequenceNum)) {
        return;
    }
    if (pageLead.hasError()) {
        ServiceError error = pageLead.getError();
        if (error != null) {
            commonSectionFetchOnCatch(new MwException((MwServiceError) error), startSequenceNum);
        } else {
            commonSectionFetchOnCatch(new IOException(getResources().getString(R.string.error_unknown)), startSequenceNum);
        }
        return;
    }
    Page page = pageLead.toPage(model.getTitle());
    model.setPage(page);
    model.setTitle(page.getTitle());
    editHandler.setPage(model.getPage());
    if (page.getTitle().getDescription() == null) {
        app.getSessionFunnel().noDescription();
    }
    layoutLeadImage(() -> {
        if (!fragment.isAdded()) {
            return;
        }
        fragment.callback().onPageInvalidateOptionsMenu();
        pageLoadRemainingSections(sequenceNumber.get());
    });
    // Update our history entry, in case the Title was changed (i.e. normalized)
    final HistoryEntry curEntry = model.getCurEntry();
    model.setCurEntry(new HistoryEntry(model.getTitle(), curEntry.getTimestamp(), curEntry.getSource()));
    // Fetch larger thumbnail URL from the network, and save it to our DB.
    new PageImagesClient().request(model.getTitle().getWikiSite(), Collections.singletonList(model.getTitle()), new PageImagesClient.Callback() {

        @Override
        public void success(@NonNull Call<MwQueryResponse> call, @NonNull Map<PageTitle, PageImage> results) {
            if (results.containsKey(model.getTitle())) {
                PageImage pageImage = results.get(model.getTitle());
                app.getDatabaseClient(PageImage.class).upsert(pageImage, PageImageHistoryContract.Image.SELECTION);
                updateThumbnail(pageImage.getImageName());
            }
        }

        @Override
        public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
            L.w(caught);
        }
    });
}
Also used : MwServiceError(org.wikipedia.dataclient.mwapi.MwServiceError) ServiceError(org.wikipedia.dataclient.ServiceError) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) MwException(org.wikipedia.dataclient.mwapi.MwException) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage) IOException(java.io.IOException) PageImage(org.wikipedia.pageimages.PageImage) MwServiceError(org.wikipedia.dataclient.mwapi.MwServiceError) PageImagesClient(org.wikipedia.pageimages.PageImagesClient) HistoryEntry(org.wikipedia.history.HistoryEntry)

Aggregations

MwServiceError (org.wikipedia.dataclient.mwapi.MwServiceError)3 MwException (org.wikipedia.dataclient.mwapi.MwException)2 IOException (java.io.IOException)1 ServiceError (org.wikipedia.dataclient.ServiceError)1 MwQueryResponse (org.wikipedia.dataclient.mwapi.MwQueryResponse)1 HistoryEntry (org.wikipedia.history.HistoryEntry)1 PageImage (org.wikipedia.pageimages.PageImage)1 PageImagesClient (org.wikipedia.pageimages.PageImagesClient)1 ReadingListPage (org.wikipedia.readinglist.database.ReadingListPage)1