|
1 | 1 | package com.auth0.net; |
2 | 2 |
|
3 | 3 | import com.auth0.client.MockServer; |
4 | | -import com.auth0.exception.Auth0Exception; |
5 | 4 | import com.auth0.exception.APIException; |
| 5 | +import com.auth0.exception.Auth0Exception; |
6 | 6 | import com.auth0.json.auth.TokenHolder; |
7 | 7 | import com.fasterxml.jackson.core.JsonParseException; |
8 | 8 | import com.fasterxml.jackson.core.JsonProcessingException; |
@@ -214,6 +214,30 @@ public void shouldParseJSONErrorResponseWithError() throws Exception { |
214 | 214 | assertThat(authException.getStatusCode(), is(400)); |
215 | 215 | } |
216 | 216 |
|
| 217 | + @SuppressWarnings("RedundantCast") |
| 218 | + @Test |
| 219 | + public void shouldParseJSONErrorResponseWithDescriptionAndExtraProperties() throws Exception { |
| 220 | + CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType); |
| 221 | + server.jsonResponse(AUTH_ERROR_WITH_DESCRIPTION_AND_EXTRA_PROPERTIES, 400); |
| 222 | + Exception exception = null; |
| 223 | + try { |
| 224 | + request.execute(); |
| 225 | + server.takeRequest(); |
| 226 | + } catch (Exception e) { |
| 227 | + exception = e; |
| 228 | + } |
| 229 | + assertThat(exception, is(notNullValue())); |
| 230 | + assertThat(exception, is(instanceOf(APIException.class))); |
| 231 | + assertThat(exception.getCause(), is(nullValue())); |
| 232 | + assertThat(exception.getMessage(), is("Request failed with status code 400: Multifactor authentication required")); |
| 233 | + APIException authException = (APIException) exception; |
| 234 | + assertThat(authException.getDescription(), is("Multifactor authentication required")); |
| 235 | + assertThat(authException.getError(), is("mfa_required")); |
| 236 | + assertThat(authException.getValue("mfa_token"), is((Object) "Fe26...Ha")); |
| 237 | + assertThat(authException.getValue("non_existing_key"), is(nullValue())); |
| 238 | + assertThat(authException.getStatusCode(), is(400)); |
| 239 | + } |
| 240 | + |
217 | 241 | @Test |
218 | 242 | public void shouldParseJSONErrorResponseWithDescription() throws Exception { |
219 | 243 | CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType); |
@@ -274,6 +298,7 @@ public void shouldParsePlainTextErrorResponse() throws Exception { |
274 | 298 | APIException authException = (APIException) exception; |
275 | 299 | assertThat(authException.getDescription(), is("A plain-text error response")); |
276 | 300 | assertThat(authException.getError(), is(nullValue())); |
| 301 | + assertThat(authException.getValue("non_existing_key"), is(nullValue())); |
277 | 302 | assertThat(authException.getStatusCode(), is(400)); |
278 | 303 | } |
279 | 304 |
|
|
0 commit comments