Search in sources :

Example 11 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project firebase-android-sdk by firebase.

the class DefaultSettingsSpiCallTest method testHandleResponse_requestNotSuccessful.

public void testHandleResponse_requestNotSuccessful() throws IOException {
    final HttpResponse mockHttpResponse = mock(HttpResponse.class);
    when(mockHttpResponse.code()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR);
    assertNull(defaultSettingsSpiCall.handleResponse(mockHttpResponse));
    verify(mockHttpResponse, never()).body();
    verify(mockLogger, times(1)).e(eq("Settings request failed; (status: " + HttpURLConnection.HTTP_INTERNAL_ERROR + ") from " + TEST_URL));
}
Also used : HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse)

Example 12 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project firebase-android-sdk by firebase.

the class DefaultSettingsSpiCall method invoke.

@Override
public JSONObject invoke(SettingsRequest requestData, boolean dataCollectionToken) {
    if (!dataCollectionToken) {
        throw new RuntimeException("An invalid data collection token was used.");
    }
    JSONObject toReturn = null;
    try {
        final Map<String, String> queryParams = getQueryParamsFor(requestData);
        HttpGetRequest httpRequest = createHttpGetRequest(queryParams);
        httpRequest = applyHeadersTo(httpRequest, requestData);
        logger.d("Requesting settings from " + url);
        logger.v("Settings query params were: " + queryParams);
        final HttpResponse httpResponse = httpRequest.execute();
        toReturn = handleResponse(httpResponse);
    } catch (IOException e) {
        logger.e("Settings request failed.", e);
        toReturn = null;
    }
    return toReturn;
}
Also used : JSONObject(org.json.JSONObject) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) HttpGetRequest(com.google.firebase.crashlytics.internal.network.HttpGetRequest) IOException(java.io.IOException)

Aggregations

HttpResponse (com.google.firebase.crashlytics.internal.network.HttpResponse)12 IOException (java.io.IOException)6 Logger (com.google.firebase.crashlytics.internal.Logger)4 HttpRequest (com.google.firebase.crashlytics.internal.network.HttpRequest)4 JSONObject (org.json.JSONObject)3 HttpGetRequest (com.google.firebase.crashlytics.internal.network.HttpGetRequest)2