mirror of
https://github.com/nextcloud/android.git
synced 2024-12-01 03:43:43 +03:00
add response-body (if available) to exception if request failed (ref https://github.com/nextcloud/Android-SingleSignOn/issues/35)
This commit is contained in:
parent
704a41b281
commit
d9080650ac
1 changed files with 13 additions and 1 deletions
|
@ -49,10 +49,12 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
|||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
@ -213,7 +215,17 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
|||
if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
|
||||
return method.getResponseBodyAsStream();
|
||||
} else {
|
||||
throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED, new IllegalStateException(String.valueOf(status)));
|
||||
StringBuilder total = new StringBuilder();
|
||||
InputStream inputStream = method.getResponseBodyAsStream();
|
||||
// If response body is available
|
||||
if(inputStream != null) {
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
|
||||
for (String line; (line = r.readLine()) != null; ) {
|
||||
total.append(line).append('\n');
|
||||
}
|
||||
Log_OC.e(TAG, total.toString());
|
||||
}
|
||||
throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED, new IllegalStateException(String.valueOf(status), new Throwable(total.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue