Skip to content

Commit 20878ac

Browse files
committed
UaaException: include server error payload
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
1 parent 6317464 commit 20878ac

File tree

6 files changed

+66
-12
lines changed

6 files changed

+66
-12
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/util/ErrorPayloadMappers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public static ErrorPayloadMapper uaa(ObjectMapper objectMapper) {
101101
String error = (String) map.get("error");
102102
String errorDescription = (String) map.get("error_description");
103103

104-
return new UaaException(statusCode, error, errorDescription);
104+
return new UaaException(
105+
statusCode, error, errorDescription, payload);
105106
}));
106107
}
107108

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/util/ErrorPayloadMappersTest.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,26 @@ void uaaClientError() throws IOException {
327327
assertThat(t)
328328
.isInstanceOf(UaaException.class)
329329
.hasMessage("unauthorized: Bad credentials")
330-
.extracting("statusCode", "error", "errorDescription")
330+
.extracting(
331+
"statusCode",
332+
"error",
333+
"errorDescription",
334+
"payload")
331335
.containsExactly(
332336
BAD_REQUEST.code(),
333337
"unauthorized",
334-
"Bad credentials"))
338+
"Bad credentials",
339+
"{\n"
340+
+ " \"error\": \"unauthorized\",\n"
341+
+ " \"error_description\": \"Bad"
342+
+ " credentials\",\n"
343+
+ " \"extra_information\": {\n"
344+
+ " \"some\": [\n"
345+
+ " \"extra\",\n"
346+
+ " \"information\"\n"
347+
+ " ]\n"
348+
+ " }\n"
349+
+ "}\n"))
335350
.verify(Duration.ofSeconds(1));
336351
}
337352

@@ -370,11 +385,26 @@ void uaaServerError() throws IOException {
370385
assertThat(t)
371386
.isInstanceOf(UaaException.class)
372387
.hasMessage("unauthorized: Bad credentials")
373-
.extracting("statusCode", "error", "errorDescription")
388+
.extracting(
389+
"statusCode",
390+
"error",
391+
"errorDescription",
392+
"payload")
374393
.containsExactly(
375394
INTERNAL_SERVER_ERROR.code(),
376395
"unauthorized",
377-
"Bad credentials"))
396+
"Bad credentials",
397+
"{\n"
398+
+ " \"error\": \"unauthorized\",\n"
399+
+ " \"error_description\": \"Bad"
400+
+ " credentials\",\n"
401+
+ " \"extra_information\": {\n"
402+
+ " \"some\": [\n"
403+
+ " \"extra\",\n"
404+
+ " \"information\"\n"
405+
+ " ]\n"
406+
+ " }\n"
407+
+ "}\n"))
378408
.verify(Duration.ofSeconds(1));
379409
}
380410

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
22
"error": "unauthorized",
3-
"error_description": "Bad credentials"
3+
"error_description": "Bad credentials",
4+
"extra_information": {
5+
"some": [
6+
"extra",
7+
"information"
8+
]
9+
}
410
}

cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/UaaException.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@
2323
*/
2424
public final class UaaException extends AbstractCloudFoundryException {
2525

26-
private static final long serialVersionUID = 2191208398880609800L;
26+
private static final long serialVersionUID = -474523104186506972L;
2727

2828
private final String error;
2929

3030
private final String errorDescription;
3131

32+
private final String payload;
33+
3234
/**
3335
* Creates a new instance
3436
*
3537
* @param statusCode the status code
3638
* @param error the error
3739
* @param errorDescription the error description
3840
*/
39-
public UaaException(Integer statusCode, String error, String errorDescription) {
41+
public UaaException(Integer statusCode, String error, String errorDescription, String payload) {
4042
super(statusCode, String.format("%s: %s", error, errorDescription));
4143
this.error = error;
4244
this.errorDescription = errorDescription;
45+
this.payload = payload;
4346
}
4447

4548
/**
@@ -55,4 +58,11 @@ public String getError() {
5558
public String getErrorDescription() {
5659
return this.errorDescription;
5760
}
61+
62+
/**
63+
* Returns the full error payload
64+
*/
65+
public String getPayload() {
66+
return payload;
67+
}
5868
}

cloudfoundry-client/src/test/java/org/cloudfoundry/uaa/UaaExceptionTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ final class UaaExceptionTest {
2424

2525
@Test
2626
void test() {
27-
assertThat(new UaaException(-1, "test-error", "test-error-description"))
27+
assertThat(
28+
new UaaException(
29+
-1, "test-error", "test-error-description", "some error payload"))
2830
.hasNoCause()
2931
.hasMessage("test-error: test-error-description")
30-
.extracting("statusCode", "error", "errorDescription")
31-
.containsExactly(-1, "test-error", "test-error-description");
32+
.extracting("statusCode", "error", "errorDescription", "payload")
33+
.containsExactly(-1, "test-error", "test-error-description", "some error payload");
3234
}
3335
}

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/useradmin/DefaultUserAdminTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,12 @@ private static void requestCreateUaaUserAlreadyExists(UaaClient uaaClient) {
704704
.userName("test-username")
705705
.build()))
706706
.thenReturn(
707-
Mono.error(new UaaException(409, "test-error", "test-error-description")));
707+
Mono.error(
708+
new UaaException(
709+
409,
710+
"test-error",
711+
"test-error-description",
712+
"some error payload")));
708713
}
709714

710715
private static void requestCreateUser(CloudFoundryClient cloudFoundryClient) {

0 commit comments

Comments
 (0)