Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public static ErrorPayloadMapper uaa(ObjectMapper objectMapper) {
String error = (String) map.get("error");
String errorDescription = (String) map.get("error_description");

return new UaaException(statusCode, error, errorDescription);
return new UaaException(
statusCode, error, errorDescription, payload);
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,26 @@ void uaaClientError() throws IOException {
assertThat(t)
.isInstanceOf(UaaException.class)
.hasMessage("unauthorized: Bad credentials")
.extracting("statusCode", "error", "errorDescription")
.extracting(
"statusCode",
"error",
"errorDescription",
"payload")
.containsExactly(
BAD_REQUEST.code(),
"unauthorized",
"Bad credentials"))
"Bad credentials",
"{\n"
+ " \"error\": \"unauthorized\",\n"
+ " \"error_description\": \"Bad"
+ " credentials\",\n"
+ " \"extra_information\": {\n"
+ " \"some\": [\n"
+ " \"extra\",\n"
+ " \"information\"\n"
+ " ]\n"
+ " }\n"
+ "}\n"))
.verify(Duration.ofSeconds(1));
}

Expand Down Expand Up @@ -370,11 +385,26 @@ void uaaServerError() throws IOException {
assertThat(t)
.isInstanceOf(UaaException.class)
.hasMessage("unauthorized: Bad credentials")
.extracting("statusCode", "error", "errorDescription")
.extracting(
"statusCode",
"error",
"errorDescription",
"payload")
.containsExactly(
INTERNAL_SERVER_ERROR.code(),
"unauthorized",
"Bad credentials"))
"Bad credentials",
"{\n"
+ " \"error\": \"unauthorized\",\n"
+ " \"error_description\": \"Bad"
+ " credentials\",\n"
+ " \"extra_information\": {\n"
+ " \"some\": [\n"
+ " \"extra\",\n"
+ " \"information\"\n"
+ " ]\n"
+ " }\n"
+ "}\n"))
.verify(Duration.ofSeconds(1));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"error": "unauthorized",
"error_description": "Bad credentials"
"error_description": "Bad credentials",
"extra_information": {
"some": [
"extra",
"information"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@
*/
public final class UaaException extends AbstractCloudFoundryException {

private static final long serialVersionUID = 2191208398880609800L;
private static final long serialVersionUID = -474523104186506972L;

private final String error;

private final String errorDescription;

private final String payload;

/**
* Creates a new instance
*
* @param statusCode the status code
* @param error the error
* @param errorDescription the error description
*/
public UaaException(Integer statusCode, String error, String errorDescription) {
public UaaException(Integer statusCode, String error, String errorDescription, String payload) {
super(statusCode, String.format("%s: %s", error, errorDescription));
this.error = error;
this.errorDescription = errorDescription;
this.payload = payload;
}

/**
Expand All @@ -55,4 +58,11 @@ public String getError() {
public String getErrorDescription() {
return this.errorDescription;
}

/**
* Returns the full error payload
*/
public String getPayload() {
return payload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ final class UaaExceptionTest {

@Test
void test() {
assertThat(new UaaException(-1, "test-error", "test-error-description"))
assertThat(
new UaaException(
-1, "test-error", "test-error-description", "some error payload"))
.hasNoCause()
.hasMessage("test-error: test-error-description")
.extracting("statusCode", "error", "errorDescription")
.containsExactly(-1, "test-error", "test-error-description");
.extracting("statusCode", "error", "errorDescription", "payload")
.containsExactly(-1, "test-error", "test-error-description", "some error payload");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,12 @@ private static void requestCreateUaaUserAlreadyExists(UaaClient uaaClient) {
.userName("test-username")
.build()))
.thenReturn(
Mono.error(new UaaException(409, "test-error", "test-error-description")));
Mono.error(
new UaaException(
409,
"test-error",
"test-error-description",
"some error payload")));
}

private static void requestCreateUser(CloudFoundryClient cloudFoundryClient) {
Expand Down