Skip to content

Commit

Permalink
Merge pull request #69 from serhiyivanov/support-message-templating-f…
Browse files Browse the repository at this point in the history
…ields

added message templating related fields
  • Loading branch information
vladimanaev authored Sep 11, 2022
2 parents 2735db4 + 84d55db commit faed436
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.taboola</groupId>
<artifactId>backstage-api-java-client</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Backstage API Java Client</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/taboola/backstage/Backstage.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static class BackstageBuilder {
private static final String DEFAULT_BACKSTAGE_HOST = "https://backstage.taboola.com/backstage/";
private static final String DEFAULT_AUTH_BACKSTAGE_HOST = "https://authentication.taboola.com/authentication/";
private static final String DEFAULT_USER_AGENT = "Taboola Java Client";
private static final String VERSION = "1.1.2";
private static final String VERSION = "1.1.3";
private static final SerializationConfig DEFAULT_SERIALIZATION_CONFIG = new SerializationConfig();

private String baseUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static String parseError(APIError error) {
return "";
}

return String.format(". Response payload status [%s], message [%s], offending field [%s], message code [%s]", error.getHttpStatus(), error.getMessage(), error.getOffendingField(), error.getMessageCode());
return String.format(". Response payload status [%s], message [%s], offending field [%s], message code [%s], message code template [%s], template parameters [%s] ", error.getHttpStatus(), error.getMessage(), error.getOffendingField(), error.getMessageCode(), error.getMessageCodeEnglishTemplate(), error.getTemplateParameters());
}

public APIError getError() {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/taboola/backstage/model/APIError.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.taboola.backstage.model;

import java.util.Collection;
import java.util.List;

/**
* Created by vladi
* Date: 10/12/2017
Expand All @@ -14,6 +17,8 @@ public class APIError {
private String message;
private String offendingField;
private String messageCode;
private String messageCodeEnglishTemplate;
private List<String> templateParameters;

public APIError() {
//for jackson
Expand All @@ -25,10 +30,16 @@ public APIError(String message, int httpStatus) {
}

public APIError(String message, int httpStatus, String offendingField, String messageCode) {
this(message, httpStatus, offendingField, messageCode, null, null);
}

public APIError(String message, int httpStatus, String offendingField, String messageCode, String messageCodeEnglishTemplate, List<String> templateParameters) {
this.message = message;
this.httpStatus = httpStatus;
this.offendingField = offendingField;
this.messageCode = messageCode;
this.messageCodeEnglishTemplate = messageCodeEnglishTemplate;
this.templateParameters = templateParameters;
}

public int getHttpStatus() {
Expand Down Expand Up @@ -63,13 +74,32 @@ public void setMessageCode(String messageCode) {
this.messageCode = messageCode;
}

public String getMessageCodeEnglishTemplate() {
return messageCodeEnglishTemplate;
}

public void setMessageCodeEnglishTemplate(String messageCodeEnglishTemplate) {
this.messageCodeEnglishTemplate = messageCodeEnglishTemplate;
}

public Collection<String> getTemplateParameters() {
return templateParameters;
}

public void setTemplateParameters(List<String> templateParameters) {
this.templateParameters = templateParameters;
}

@Override
public String toString() {
return "APIError{" +
"httpStatus=" + httpStatus +
", message='" + message + '\'' +
", offendingField='" + offendingField + '\'' +
", messageCode='" + messageCode + '\'' +
", messageCodeEnglishTemplate='" + messageCodeEnglishTemplate + '\'' +
", templateParameters=" + templateParameters +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public void testParseError_whenErrorMsgContainsPercentSign_expectingValidFormatF
apiError = testInstance.normalizeError(apiError);
BackstageAPIException ex = new BackstageAPIRequestException(400, apiError);
logger.info(ex);
assertEquals("Failed to perform API call with response code [400]. Response payload status [400], message [Cpc boost value must be between -99% and 100%], offending field [null], message code [null]", ex.getMessage());
assertEquals("Failed to perform API call with response code [400]. Response payload status [400], message [Cpc boost value must be between -99% and 100%], offending field [null], message code [null], message code template [null], template parameters [null] ", ex.getMessage());
}
}

0 comments on commit faed436

Please sign in to comment.