Search in sources :

Example 1 with RateLimitException

use of com.auth0.exception.RateLimitException in project auth0-java by auth0.

the class BaseRequestTest method alwaysCloseResponseOnRateLimitException.

@Test
public void alwaysCloseResponseOnRateLimitException() {
    Exception exception = null;
    try {
        new MockBaseRequest<String>(client) {

            @Override
            protected String parseResponse(Response response) throws Auth0Exception {
                throw new RateLimitException(-1, -1, -1);
            }
        }.execute();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(RateLimitException.class)));
    assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
    verify(response, times(1)).close();
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) Auth0Exception(com.auth0.exception.Auth0Exception) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) Test(org.junit.Test)

Example 2 with RateLimitException

use of com.auth0.exception.RateLimitException in project auth0-java by auth0.

the class CustomRequestTest method shouldParseRateLimitsHeaders.

@Test
public void shouldParseRateLimitsHeaders() {
    CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
    server.rateLimitReachedResponse(100, 10, 5);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(RateLimitException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
    RateLimitException rateLimitException = (RateLimitException) exception;
    assertThat(rateLimitException.getDescription(), is("Rate limit reached"));
    assertThat(rateLimitException.getError(), is(nullValue()));
    assertThat(rateLimitException.getValue("non_existing_key"), is(nullValue()));
    assertThat(rateLimitException.getStatusCode(), is(429));
    assertThat(rateLimitException.getLimit(), is(100L));
    assertThat(rateLimitException.getRemaining(), is(10L));
    assertThat(rateLimitException.getReset(), is(5L));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) List(java.util.List) Auth0Exception(com.auth0.exception.Auth0Exception) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException)

Example 3 with RateLimitException

use of com.auth0.exception.RateLimitException in project auth0-java by auth0.

the class MultipartRequestTest method shouldParseRateLimitsHeaders.

@Test
public void shouldParseRateLimitsHeaders() {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.rateLimitReachedResponse(100, 10, 5);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(RateLimitException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
    RateLimitException rateLimitException = (RateLimitException) exception;
    assertThat(rateLimitException.getDescription(), is("Rate limit reached"));
    assertThat(rateLimitException.getError(), is(nullValue()));
    assertThat(rateLimitException.getValue("non_existing_key"), is(nullValue()));
    assertThat(rateLimitException.getStatusCode(), is(429));
    assertThat(rateLimitException.getLimit(), is(100L));
    assertThat(rateLimitException.getRemaining(), is(10L));
    assertThat(rateLimitException.getReset(), is(5L));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 4 with RateLimitException

use of com.auth0.exception.RateLimitException in project auth0-java by auth0.

the class MultipartRequestTest method shouldDefaultRateLimitsHeadersWhenMissing.

@Test
public void shouldDefaultRateLimitsHeadersWhenMissing() {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.rateLimitReachedResponse(-1, -1, -1);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(RateLimitException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
    RateLimitException rateLimitException = (RateLimitException) exception;
    assertThat(rateLimitException.getDescription(), is("Rate limit reached"));
    assertThat(rateLimitException.getError(), is(nullValue()));
    assertThat(rateLimitException.getValue("non_existing_key"), is(nullValue()));
    assertThat(rateLimitException.getStatusCode(), is(429));
    assertThat(rateLimitException.getLimit(), is(-1L));
    assertThat(rateLimitException.getRemaining(), is(-1L));
    assertThat(rateLimitException.getReset(), is(-1L));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 5 with RateLimitException

use of com.auth0.exception.RateLimitException in project auth0-java by auth0.

the class CustomRequestTest method shouldDefaultRateLimitsHeadersWhenMissing.

@Test
public void shouldDefaultRateLimitsHeadersWhenMissing() {
    CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
    server.rateLimitReachedResponse(-1, -1, -1);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(RateLimitException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
    RateLimitException rateLimitException = (RateLimitException) exception;
    assertThat(rateLimitException.getDescription(), is("Rate limit reached"));
    assertThat(rateLimitException.getError(), is(nullValue()));
    assertThat(rateLimitException.getValue("non_existing_key"), is(nullValue()));
    assertThat(rateLimitException.getStatusCode(), is(429));
    assertThat(rateLimitException.getLimit(), is(-1L));
    assertThat(rateLimitException.getRemaining(), is(-1L));
    assertThat(rateLimitException.getReset(), is(-1L));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) List(java.util.List) Auth0Exception(com.auth0.exception.Auth0Exception) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException)

Aggregations

APIException (com.auth0.exception.APIException)5 Auth0Exception (com.auth0.exception.Auth0Exception)5 RateLimitException (com.auth0.exception.RateLimitException)5 IOException (java.io.IOException)5 JsonParseException (com.fasterxml.jackson.core.JsonParseException)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 List (java.util.List)4 ExpectedException (org.junit.rules.ExpectedException)4 RecordedMultipartRequest (com.auth0.net.multipart.RecordedMultipartRequest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Test (org.junit.Test)1