Extend ExceptionInfo with map info + EntityNotFound info (#1901)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -268,9 +268,8 @@ public class ResponseExceptionHandler {
|
||||
response.setExceptionClass(ex.getClass().getName());
|
||||
if (ex instanceof AbstractServerRtException) {
|
||||
response.setErrorCode(((AbstractServerRtException) ex).getError().getKey());
|
||||
response.setInfo(((AbstractServerRtException) ex).getInfo());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,81 +9,22 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.json.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* A exception model rest representation with JSON annotations for response
|
||||
* bodies in case of RESTful exception occurrence.
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public class ExceptionInfo {
|
||||
|
||||
private String exceptionClass;
|
||||
private String errorCode;
|
||||
private String message;
|
||||
private List<String> parameters;
|
||||
|
||||
/**
|
||||
* @return the exceptionClass
|
||||
*/
|
||||
public String getExceptionClass() {
|
||||
return exceptionClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exceptionClass
|
||||
* the exceptionClass to set
|
||||
*/
|
||||
public void setExceptionClass(final String exceptionClass) {
|
||||
this.exceptionClass = exceptionClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameters
|
||||
*/
|
||||
public List<String> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameters
|
||||
* the parameters to set
|
||||
*/
|
||||
public void setParameters(final List<String> parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the errorCode
|
||||
*/
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param errorCode
|
||||
* the errorCode to set
|
||||
*/
|
||||
public void setErrorCode(final String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message to set
|
||||
*/
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
private Map<String, Object> info;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ package org.eclipse.hawkbit.rest.json.model;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -30,15 +30,15 @@ public class ExceptionInfoTest {
|
||||
final String knownExceptionClass = "hawkbit.test.exception.Class";
|
||||
final String knownErrorCode = "hawkbit.error.code.Known";
|
||||
final String knownMessage = "a known message";
|
||||
final List<String> knownParameters = new ArrayList<>();
|
||||
knownParameters.add("param1");
|
||||
knownParameters.add("param2");
|
||||
final Map<String, Object> knownInfo = new HashMap<>();
|
||||
knownInfo.put("param1", "1");
|
||||
knownInfo.put("param2", 2);
|
||||
|
||||
final ExceptionInfo underTest = new ExceptionInfo();
|
||||
underTest.setErrorCode(knownErrorCode);
|
||||
underTest.setExceptionClass(knownExceptionClass);
|
||||
underTest.setMessage(knownMessage);
|
||||
underTest.setParameters(knownParameters);
|
||||
underTest.setInfo(knownInfo);
|
||||
|
||||
assertThat(underTest.getErrorCode()).as("The error code should match with the known error code in the test")
|
||||
.isEqualTo(knownErrorCode);
|
||||
@@ -47,8 +47,7 @@ public class ExceptionInfoTest {
|
||||
.isEqualTo(knownExceptionClass);
|
||||
assertThat(underTest.getMessage()).as("The message should match with the known error code in the test")
|
||||
.isEqualTo(knownMessage);
|
||||
assertThat(underTest.getParameters()).as("The parameters should match with the known error code in the test")
|
||||
.isEqualTo(knownParameters);
|
||||
assertThat(underTest.getInfo()).as("The parameters should match with the known error code in the test")
|
||||
.isEqualTo(knownInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user