Skip to content

Commit 3b9745c

Browse files
authored
fix: Add missing fields in error response (#2118)
* Add action field to error rest response Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Include message reason Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix order of arguments Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix arguments order in message class Signed-off-by: at670475 <andrea.tabone@broadcom.com>
1 parent f41a6a9 commit 3b9745c

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

common-service-core/src/main/java/org/zowe/apiml/message/api/ApiMessage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ public class ApiMessage {
3636
private String messageSource;
3737

3838

39-
public ApiMessage(String messageKey, MessageType messageType, String messageNumber, String messageContent) {
39+
public ApiMessage(String messageKey, MessageType messageType, String messageNumber, String messageContent, String messageAction, String messageReason) {
4040
this.messageKey = messageKey;
4141
this.messageType = messageType;
4242
this.messageNumber = messageNumber;
4343
this.messageContent = messageContent;
44+
this.messageAction = messageAction;
45+
this.messageReason = messageReason;
4446
}
4547

4648
/**

common-service-core/src/main/java/org/zowe/apiml/message/core/Message.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ public ApiMessage mapToApiMessage() {
130130
requestedKey,
131131
messageTemplate.getType(),
132132
messageTemplate.getNumber() + messageTemplate.getType().toChar(),
133-
getConvertedText());
133+
getConvertedText(),
134+
messageTemplate.getAction(),
135+
messageTemplate.getReason());
134136
}
135137

136138
/**

common-service-core/src/test/java/org/zowe/apiml/message/core/MessageTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ void testMapToView() {
108108

109109
String expectedReadableText = "No response received within the allowed time: 3000";
110110
ApiMessageView expectedApiMessageView = new ApiMessageView(Collections.singletonList(
111-
new ApiMessage("org.zowe.apiml.common.serviceTimeout", MessageType.ERROR, "ZWEAM700E", expectedReadableText)
112-
));
111+
new ApiMessage("org.zowe.apiml.common.serviceTimeout", MessageType.ERROR, "ZWEAM700E", expectedReadableText, null, null)));
113112

114113
assertEquals(expectedApiMessageView, actualApiMessageView, "ApiMessageView is different");
115114
}
@@ -120,7 +119,7 @@ void testMapToApiMessage() {
120119
ApiMessage actualApiMessage = message.mapToApiMessage();
121120

122121
String expectedReadableText = "No response received within the allowed time: 3000";
123-
ApiMessage expectedApiMessage = new ApiMessage("org.zowe.apiml.common.serviceTimeout", MessageType.ERROR, "ZWEAM700E", expectedReadableText);
122+
ApiMessage expectedApiMessage = new ApiMessage("org.zowe.apiml.common.serviceTimeout", MessageType.ERROR, "ZWEAM700E", expectedReadableText, null, null);
124123

125124
assertEquals(expectedApiMessage, actualApiMessage, "ApiMessage is different");
126125
}

gateway-service/src/test/java/org/zowe/apiml/gateway/error/check/SecurityErrorCheckTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void shouldReturnCauseMessageWhenTokenExpireException() {
7373
assertNotNull(actualResponse);
7474
assertEquals(HttpStatus.UNAUTHORIZED, actualResponse.getStatusCode());
7575
List<ApiMessage> actualMessageList = actualResponse.getBody().getMessages();
76-
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.gateway.security.expiredToken", MessageType.ERROR, "ZWEAG103E", "The token has expired")));
76+
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.gateway.security.expiredToken", MessageType.ERROR, "ZWEAG103E", "The token has expired","Obtain new token by performing an authentication request.", "The JWT token has expired.")));
7777
}
7878

7979
@Test
@@ -93,7 +93,7 @@ void shouldReturnCauseMessageWhenTokenNotValidException() {
9393

9494
assertNotNull(actualResponse.getBody());
9595
List<ApiMessage> actualMessageList = actualResponse.getBody().getMessages();
96-
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.gateway.security.invalidToken", MessageType.ERROR, "ZWEAG102E", "Token is not valid")));
96+
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.gateway.security.invalidToken", MessageType.ERROR, "ZWEAG102E", "Token is not valid", "Provide a valid token.", "The JWT token is not valid.")));
9797
}
9898

9999
@Test
@@ -114,7 +114,7 @@ void shouldReturnCauseMessageWhenBadCredentialsException() {
114114
assertNotNull(actualResponse.getBody());
115115
List<ApiMessage> actualMessageList = actualResponse.getBody().getMessages();
116116
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.security.login.invalidCredentials",
117-
MessageType.ERROR, "ZWEAG120E", "Invalid username or password for URL 'null'")));
117+
MessageType.ERROR, "ZWEAG120E", "Invalid username or password for URL 'null'", "Provide a valid username and password.", "The username and/or password are invalid.")));
118118
}
119119
}
120120

gateway-service/src/test/java/org/zowe/apiml/gateway/error/check/ServiceErrorCheckTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void givenNotFoundZuulException_whenTheRequestIsProcessed_then404IsReturned() {
6262
assertEquals(HttpStatus.NOT_FOUND, actualResponse.getStatusCode());
6363
List<ApiMessage> actualMessageList = actualResponse.getBody().getMessages();
6464
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.common.endPointNotFound",
65-
MessageType.ERROR, "ZWEAM104E", "The endpoint you are looking for 'serviceId' could not be located")));
65+
MessageType.ERROR, "ZWEAM104E", "The endpoint you are looking for 'serviceId' could not be located", "Verify that the URL of the endpoint you are trying to reach is correct.", "The endpoint you are looking for could not be located.")));
6666
}
6767

6868
@Test
@@ -77,6 +77,6 @@ void givenServiceNotAccessibleException_whenTheRequestIsProcessed_then404IsRetur
7777
assertEquals(HttpStatus.NOT_FOUND, actualResponse.getStatusCode());
7878
List<ApiMessage> actualMessageList = actualResponse.getBody().getMessages();
7979
assertThat(actualMessageList, hasItem(new ApiMessage("org.zowe.apiml.gateway.serviceUnavailable",
80-
MessageType.ERROR, "ZWEAG709E", "Service is not available at URL 'null'. Error returned: 'null'")));
80+
MessageType.ERROR, "ZWEAG709E", "Service is not available at URL 'null'. Error returned: 'null'", "Make sure that the service is running and is accessible by the URL provided in the message.", "The service is not available.")));
8181
}
8282
}

0 commit comments

Comments
 (0)