Add ability to suppress logging of known unsuccessful API calls (#5526)

This commit is contained in:
Paul Hawke 2024-02-08 15:55:56 -06:00 committed by GitHub
parent ba11f0d06e
commit c6cb97e199
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 3 deletions

View file

@ -130,6 +130,17 @@ class MediaClient @Inject constructor(
.map { it.first() }
}
/**
* Fetches Media object from the imageInfo API but suppress (known) errors
*
* @param titles the tiles to be searched for. Can be filename or template name
* @return
*/
fun getMediaSuppressingErrors(titles: String?): Single<Media> {
return responseMapper(mediaInterface.getMediaSuppressingErrors(titles))
.map { it.first() }
}
/**
* The method returns the picture of the day
*

View file

@ -1,9 +1,12 @@
package fr.free.nrw.commons.media;
import static fr.free.nrw.commons.OkHttpConnectionFactory.UnsuccessfulResponseInterceptor.SUPPRESS_ERROR_LOG_HEADER;
import io.reactivex.Single;
import java.util.Map;
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
@ -103,6 +106,17 @@ public interface MediaInterface {
MEDIA_PARAMS_WITH_CATEGORY_DETAILS)
Single<MwQueryResponse> getMedia(@Query("titles") String title);
/**
* Fetches Media object from the imageInfo API but suppress (known) errors
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" +
MEDIA_PARAMS_WITH_CATEGORY_DETAILS)
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwQueryResponse> getMediaSuppressingErrors(@Query("titles") String title);
/**
* Fetches Media object from the imageInfo API
*
@ -111,6 +125,7 @@ public interface MediaInterface {
*/
@GET("w/api.php?action=query&format=json&formatversion=2" +
MEDIA_PARAMS)
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwQueryResponse> getMediaById(@Query("pageids") String pageIds);
/**
@ -125,6 +140,7 @@ public interface MediaInterface {
Single<MwQueryResponse> getMediaWithGenerator(@Query("titles") String title);
@GET("w/api.php?format=json&action=parse&prop=text")
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwParseResponse> getPageHtml(@Query("page") String title);
/**