diff --git a/src/main/java/org/acra/util/HttpRequest.java b/src/main/java/org/acra/util/HttpRequest.java index 750424d35e..f34e16c059 100644 --- a/src/main/java/org/acra/util/HttpRequest.java +++ b/src/main/java/org/acra/util/HttpRequest.java @@ -41,7 +41,9 @@ public final class HttpRequest { private static final int HTTP_SUCCESS = 200; private static final int HTTP_REDIRECT = 300; private static final int HTTP_CLIENT_ERROR = 400; + private static final int HTTP_UNAUTHORIZED = 401; private static final int HTTP_FORBIDDEN = 403; + private static final int HTTP_METHOD_NOT_ALLOWED = 405; private static final int HTTP_CONFLICT = 409; private static final int MAX_HTTP_CODE = 600; @@ -160,17 +162,25 @@ public void send(@NonNull Context context, @NonNull URL url, @NonNull Method met if ((responseCode >= HTTP_SUCCESS) && (responseCode < HTTP_REDIRECT)) { // All is good ACRA.log.i(LOG_TAG, "Request received by server"); + } else if (responseCode == HTTP_UNAUTHORIZED) { + //401 means the server rejected the authentication. The request must not be repeated. Discard it. + //This probably means that nothing can be sent with this configuration, maybe ACRA should disable itself after it? + ACRA.log.w(LOG_TAG, "401: Login validation error on server - request will be discarded"); } else if (responseCode == HTTP_FORBIDDEN) { // 403 is an explicit data validation refusal from the server. The request must not be repeated. Discard it. - ACRA.log.w(LOG_TAG, "Data validation error on server - request will be discarded"); + ACRA.log.w(LOG_TAG, "403: Data validation error on server - request will be discarded"); + } else if (responseCode == HTTP_METHOD_NOT_ALLOWED) { + //405 means the server doesn't allow this request method. The request must not be repeated. Discard it. + //This probably means that nothing can be sent with this configuration, maybe ACRA should disable itself after it? + ACRA.log.w(LOG_TAG, "405: Server rejected Http " + method + " - request will be discarded"); } else if (responseCode == HTTP_CONFLICT) { // 409 means that the report has been received already. So we can discard it. - ACRA.log.w(LOG_TAG, "Server has already received this post - request will be discarded"); + ACRA.log.w(LOG_TAG, "409: Server has already received this post - request will be discarded"); } else if ((responseCode >= HTTP_CLIENT_ERROR) && (responseCode < MAX_HTTP_CODE)) { ACRA.log.w(LOG_TAG, "Could not send ACRA Post responseCode=" + responseCode + " message=" + urlConnection.getResponseMessage()); throw new IOException("Host returned error code " + responseCode); } else { - ACRA.log.w(LOG_TAG, "Could not send ACRA Post - request will be discarded responseCode=" + responseCode + " message=" + urlConnection.getResponseMessage()); + ACRA.log.w(LOG_TAG, "Could not send ACRA Post - request will be discarded. responseCode=" + responseCode + " message=" + urlConnection.getResponseMessage()); } urlConnection.disconnect();