Commit 4430bf72 authored by Florian Schäfer's avatar Florian Schäfer

Use the right API names when logging messages in the API query client

parent 1cad5e6e
Pipeline #25324403 passed with stages
in 5 minutes and 54 seconds
...@@ -37,6 +37,8 @@ public abstract class ApiQuery<T> { ...@@ -37,6 +37,8 @@ public abstract class ApiQuery<T> {
return url.toString(); return url.toString();
} }
public abstract String getApiName();
public abstract HttpClient getHttpClient(); public abstract HttpClient getHttpClient();
/** /**
......
...@@ -76,16 +76,18 @@ public final class ApiQueryClient { ...@@ -76,16 +76,18 @@ public final class ApiQueryClient {
response = query.getHttpClient().connect(); response = query.getHttpClient().connect();
} catch (IOException e) { } catch (IOException e) {
throw new IOException(I18n.tr( throw new IOException(I18n.tr(
// i18n: {0} is the name of the exception, {1} is the message of the exception. Typical values would be: {0}="UnknownHostException" {1}="www.wikidata.org" // i18n: {0} is the API name, {1} is the name of the exception, {2} is the message of the exception.
"Could not connect to the Wikidata Action API, probably a network issue or the website is currently offline ({0}: {1})", // i18n: Typical values would be: {0}="Wikidata Action API" {1}="UnknownHostException" {2}="www.wikidata.org"
"Could not connect to the {0}, probably a network issue or the website is currently offline ({1}: {2})",
e.getClass().getSimpleName(), e.getClass().getSimpleName(),
e.getLocalizedMessage() e.getLocalizedMessage()
), e); ), e);
} }
if (response.getResponseCode() != 200) { if (response.getResponseCode() != 200) {
throw new IOException(I18n.tr( throw new IOException(I18n.tr(
// i18n: {0} is the response code, {1} is the response message. Typical values would be: {0}=404 {1}="Not Found" // i18n: {0} is the API name, {1} is the response code, {2} is the response message.
"The Wikidata Action API responded with an unexpected response code: {0} {1}", // i18n: Typical values would be: {0}="Wikidata Action API" {1}=404 {2}="Not Found"
"The {0} responded with an unexpected response code: {1} {2}",
response.getResponseCode(), response.getResponseCode(),
response.getResponseMessage() response.getResponseMessage()
)); ));
...@@ -93,8 +95,9 @@ public final class ApiQueryClient { ...@@ -93,8 +95,9 @@ public final class ApiQueryClient {
final String errorHeader = response.getHeaderField("MediaWiki-API-Error"); final String errorHeader = response.getHeaderField("MediaWiki-API-Error");
if (errorHeader != null) { if (errorHeader != null) {
final IOException wrapperEx = new IOException(I18n.tr( final IOException wrapperEx = new IOException(I18n.tr(
// I18n: {0} is the query, normally as URL. {1} is the error message returned from the API // I18n: {0} is the API name, {1} is the query, normally as URL. {2} is the error message returned from the API
"The Wikidata Action API reported an invalid query for {0} ({1}). This is a programming error, please report to the Wikipedia plugin.", "The {0} reported an invalid query for {1} ({2}). This is a programming error, please report to the Wikipedia plugin.",
query.getApiName(),
query.getCacheKey(), query.getCacheKey(),
errorHeader errorHeader
)); ));
...@@ -116,8 +119,8 @@ public final class ApiQueryClient { ...@@ -116,8 +119,8 @@ public final class ApiQueryClient {
wrapper = new IOException(I18n.tr("The JSON response from the Wikidata Action API can't be decoded!"), exception); wrapper = new IOException(I18n.tr("The JSON response from the Wikidata Action API can't be decoded!"), exception);
} else { } else {
wrapper = new IOException(I18n.tr( wrapper = new IOException(I18n.tr(
// i18n: {0} is the name of the Exception, {1} is the message that exception provides // i18n: {0} is the name of the API, {1} is the name of the Exception, {2} is the message that exception provides
"When reading the JSON response from the Wikidata Action API, an error occured! ({0}: {1})", "When reading the JSON response from the {0}, an error occured! ({1}: {2})",
exception.getClass().getSimpleName(), exception.getClass().getSimpleName(),
exception.getLocalizedMessage() exception.getLocalizedMessage()
), exception); ), exception);
......
...@@ -21,6 +21,7 @@ public class WdqApiQuery<T> extends ApiQuery<T> { ...@@ -21,6 +21,7 @@ public class WdqApiQuery<T> extends ApiQuery<T> {
this.queryString = Objects.requireNonNull(queryString); this.queryString = Objects.requireNonNull(queryString);
} }
@Override
public String getApiName() { public String getApiName() {
return "Wikidata Query Service API"; return "Wikidata Query Service API";
} }
......
...@@ -73,6 +73,11 @@ public final class WikidataActionApiQuery<T> extends ApiQuery<T> { ...@@ -73,6 +73,11 @@ public final class WikidataActionApiQuery<T> extends ApiQuery<T> {
return getUrl().toString() + '?' + getQuery(); return getUrl().toString() + '?' + getQuery();
} }
@Override
public String getApiName() {
return "Wikidata Action API";
}
@Override @Override
public HttpClient getHttpClient() { public HttpClient getHttpClient() {
return HttpClient.create(getUrl(), "POST") return HttpClient.create(getUrl(), "POST")
......
...@@ -28,6 +28,11 @@ public class WikipediaActionApiQuery<T> extends ApiQuery<T> { ...@@ -28,6 +28,11 @@ public class WikipediaActionApiQuery<T> extends ApiQuery<T> {
return queryString; return queryString;
} }
@Override
public String getApiName() {
return "Wikipedia Action API";
}
@Override @Override
public HttpClient getHttpClient() { public HttpClient getHttpClient() {
return HttpClient.create(getUrl(), "POST") return HttpClient.create(getUrl(), "POST")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment