Skip to content

Commit

Permalink
Preserve error response body in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jul 4, 2021
1 parent 3009221 commit 9fe6b06
Show file tree
Hide file tree
Showing 48 changed files with 364 additions and 210 deletions.
3 changes: 3 additions & 0 deletions assets/changelog-alpha.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/Alpha 286 (2021-07-04)
Preserve error response body in more cases

/Alpha 285 (2021-07-04)
Imgur upload reliability improved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.quantumbadger.redreader.common.PrefsUtility;
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.image.AlbumInfo;
import org.quantumbadger.redreader.image.GetAlbumInfoListener;
import org.quantumbadger.redreader.image.GetImageInfoListener;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> body) {
@NonNull final Optional<FailedRequestBody> body) {
Log.e(
"AlbumListingActivity",
"getAlbumInfo call failed: " + type);
Expand Down Expand Up @@ -172,7 +173,7 @@ public void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> body) {
@NonNull final Optional<FailedRequestBody> body) {
Log.e(
"AlbumListingActivity",
"Image info request also failed: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.quantumbadger.redreader.common.PrefsUtility;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.fragments.MarkdownPreviewDialog;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.reddit.APIResponseHandler;
import org.quantumbadger.redreader.reddit.RedditAPI;

Expand Down Expand Up @@ -156,15 +157,15 @@ protected void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
type,
t,
httpStatus,
"Comment edit",
response.orElseNull());
response);

General.showResultDialog(CommentEditActivity.this, error);
General.safeDismissDialog(progressDialog);
Expand All @@ -174,7 +175,7 @@ protected void onFailure(
protected void onFailure(
@NonNull final APIFailureType type,
@Nullable final String debuggingContext,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.StringUtils;
import org.quantumbadger.redreader.fragments.MarkdownPreviewDialog;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.reddit.APIResponseHandler;
import org.quantumbadger.redreader.reddit.RedditAPI;

Expand Down Expand Up @@ -278,15 +279,15 @@ protected void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
type,
t,
httpStatus,
"Comment reply",
response.orElseNull());
"Comment reply: " + readableMessage,
response);

General.showResultDialog(CommentReplyActivity.this, error);
General.safeDismissDialog(progressDialog);
Expand All @@ -296,7 +297,7 @@ protected void onFailure(
protected void onFailure(
@NonNull final APIFailureType type,
@Nullable final String debuggingContext,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
Expand Down Expand Up @@ -327,7 +328,7 @@ protected void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {
Toast.makeText(
context,
getString(R.string.disable_replies_to_infobox_failed),
Expand All @@ -338,7 +339,7 @@ protected void onFailure(
protected void onFailure(
@NonNull final APIFailureType type,
@Nullable final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

Toast.makeText(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.SharedPrefsWrapper;
import org.quantumbadger.redreader.common.StringUtils;
import org.quantumbadger.redreader.common.datastream.SeekableInputStream;
import org.quantumbadger.redreader.fragments.ImageInfoDialog;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.image.AlbumInfo;
import org.quantumbadger.redreader.image.GetAlbumInfoListener;
import org.quantumbadger.redreader.image.GetImageInfoListener;
Expand Down Expand Up @@ -190,7 +190,7 @@ public void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> body) {
@NonNull final Optional<FailedRequestBody> body) {

// Do nothing
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> body) {
@NonNull final Optional<FailedRequestBody> body) {

General.quickToast(
ImageViewActivity.this,
Expand Down Expand Up @@ -951,7 +951,7 @@ public void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

synchronized(resultLock) {

Expand All @@ -971,7 +971,7 @@ public void onFailure(
t,
httpStatus,
uri.toString(),
body.map(StringUtils::fromUTF8).orElseNull());
body);

AndroidCommon.UI_THREAD_HANDLER.post(() -> {
final LinearLayout layout
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

synchronized(resultLock) {

Expand All @@ -1072,7 +1072,7 @@ public void onFailure(
t,
httpStatus,
audioUri.toString(),
body.map(StringUtils::fromUTF8).orElseNull());
body);

AndroidCommon.runOnUiThread(() -> {
final LinearLayout layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.quantumbadger.redreader.common.PrefsUtility;
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.StringUtils;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.http.body.HTTPRequestBodyMultipart;
import org.quantumbadger.redreader.http.body.multipart.PartFormDataBinary;
import org.quantumbadger.redreader.image.ThumbnailScaler;
Expand Down Expand Up @@ -291,8 +291,7 @@ public void onJsonParsed(
null,
null,
null,
Optional.of(
result.toString().getBytes(General.CHARSET_UTF8)));
Optional.of(new FailedRequestBody(result)));
return;
}

Expand All @@ -305,7 +304,7 @@ public void onJsonParsed(
t,
null,
t.toString(),
Optional.of(result.toString().getBytes(General.CHARSET_UTF8)));
Optional.of(new FailedRequestBody(result)));
return;
}

Expand All @@ -324,7 +323,7 @@ public void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

General.showResultDialog(
ImgurUploadActivity.this,
Expand All @@ -334,7 +333,7 @@ public void onFailure(
t,
httpStatus,
"https://api.imgur.com/3/image",
body.map(StringUtils::fromUTF8).orElseNull()));
body));

AndroidCommon.runOnUiThread(ImgurUploadActivity.this::hideLoadingOverlay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.quantumbadger.redreader.common.RRTime;
import org.quantumbadger.redreader.common.SharedPrefsWrapper;
import org.quantumbadger.redreader.common.StringUtils;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.jsonwrap.JsonArray;
import org.quantumbadger.redreader.jsonwrap.JsonObject;
import org.quantumbadger.redreader.jsonwrap.JsonValue;
Expand Down Expand Up @@ -379,7 +380,7 @@ public void onJsonParsed(
t,
null,
"Parse failure",
Optional.of(result.toString().getBytes(General.CHARSET_UTF8)));
Optional.of(new FailedRequestBody(result)));
return;
}

Expand All @@ -394,7 +395,7 @@ public void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

request = null;

Expand All @@ -408,7 +409,7 @@ public void onFailure(
t,
httpStatus,
url.toString(),
null);
body);
AndroidCommon.runOnUiThread(() -> notifications.addView(
new ErrorView(InboxListingActivity.this, error)));

Expand Down Expand Up @@ -472,15 +473,15 @@ protected void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
type,
t,
status,
"Reddit API action: Mark all as Read",
response.orElseNull());
response);
General.showResultDialog(
InboxListingActivity.this,
error);
Expand All @@ -490,7 +491,7 @@ protected void onFailure(
protected void onFailure(
@NonNull final APIFailureType type,
@Nullable final String debuggingContext,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.quantumbadger.redreader.common.PrefsUtility;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.fragments.MarkdownPreviewDialog;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.reddit.APIResponseHandler;
import org.quantumbadger.redreader.reddit.RedditAPI;

Expand Down Expand Up @@ -231,15 +232,15 @@ protected void onFailure(
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
type,
t,
status,
"PM send",
response.orElseNull());
response);

General.showResultDialog(PMSendActivity.this, error);
General.safeDismissDialog(progressDialog);
Expand All @@ -249,7 +250,7 @@ protected void onFailure(
protected void onFailure(
@NonNull final APIFailureType type,
@Nullable final String debuggingContext,
@NonNull final Optional<String> response) {
@NonNull final Optional<FailedRequestBody> response) {

final RRError error = General.getGeneralErrorForFailure(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.datastream.SeekableInputStream;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.image.AlbumInfo;
import org.quantumbadger.redreader.image.ImageInfo;
import org.quantumbadger.redreader.viewholders.VH3TextIcon;
Expand Down Expand Up @@ -163,7 +164,7 @@ public void onFailure(
@Nullable final Throwable t,
@Nullable final Integer httpStatus,
@Nullable final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

if(General.isSensitiveDebugLoggingEnabled()) {
Log.e(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.quantumbadger.redreader.common.RRTime;
import org.quantumbadger.redreader.common.TorCommon;
import org.quantumbadger.redreader.common.datastream.MemoryDataStream;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.http.HTTPBackend;
import org.quantumbadger.redreader.reddit.api.RedditOAuth;

Expand Down Expand Up @@ -165,7 +166,7 @@ public void onError(
final @CacheRequest.RequestFailureType int failureType,
final Throwable exception,
final Integer httpStatus,
@NonNull final Optional<byte[]> bodyBytes) {
@NonNull final Optional<FailedRequestBody> body) {
if(mInitiator.queueType == CacheRequest.DOWNLOAD_QUEUE_REDDIT_API
&& TorCommon.isTorEnabled()) {
HTTPBackend.getBackend().recreateHttpBackend();
Expand All @@ -177,7 +178,7 @@ public void onError(
exception,
httpStatus,
"CacheDownload onError",
bodyBytes);
body);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.datastream.SeekableInputStream;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.http.body.HTTPRequestBody;

import java.io.IOException;
Expand Down Expand Up @@ -289,7 +290,7 @@ public void notifyFailure(
final Throwable t,
final Integer httpStatus,
final String readableMessage,
@NonNull final Optional<byte[]> body) {
@NonNull final Optional<FailedRequestBody> body) {

try {
mCallbacks.onFailure(type, t, httpStatus, readableMessage, body);
Expand Down

0 comments on commit 9fe6b06

Please sign in to comment.