Skip to content

Commit

Permalink
Add more specific error messages for blocked, quarantined, and premiu…
Browse files Browse the repository at this point in the history
…m-only subreddits.
  • Loading branch information
Cguy7777 authored and QuantumBadger committed Jul 9, 2023
1 parent d6f0065 commit 72fb4af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/main/java/org/quantumbadger/redreader/common/General.kt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ object General {

CacheRequest.REQUEST_FAILURE_REQUEST -> if (status != null) {
when (status) {
400, 401, 403 -> {
400, 401, 403, 404 -> {
val uri = uriFromString(url)
var isImgurApiRequest = false
var isRedditRequest = false
Expand All @@ -294,29 +294,42 @@ object General {

val responseJson = response.flatMap { it.toJson() }

if (responseJson.asNullable()?.asObject()?.getString("reason") == "private") {
title = R.string.error_403_private_sr_title
message = R.string.error_403_private_sr_message

} else {
title = R.string.error_403_title
message = R.string.error_403_message
when(responseJson.asNullable()?.asObject()?.getString("reason")) {
"private" -> {
title = R.string.error_403_private_sr_title
message = R.string.error_403_private_sr_message
} "quarantined" -> {
title = R.string.error_403_quarantined_sr_title
message = R.string.error_403_quarantined_sr_message
} "gold_only" -> {
title = R.string.error_403_premiumonly_sr_title
message = R.string.error_403_premiumonly_sr_message
} "banned" -> {
title = R.string.error_404_banned_sr_title
message = R.string.error_404_banned_sr_message
} else -> {
if(status == 404) {
title = R.string.error_404_title
message = R.string.error_404_message
} else {
title = R.string.error_403_title
message = R.string.error_403_message
}
}
}

} else if (status == 400 && isImgurApiRequest) {
title = R.string.error_imgur_400_title
message = R.string.error_imgur_400_message
} else {
} else if (status == 404) {
title = R.string.error_404_title
message = R.string.error_404_message
} else {
title = R.string.error_403_title_nonreddit
message = R.string.error_403_message_nonreddit
}
}

404 -> {
title = R.string.error_404_title
message = R.string.error_404_message
}

429 -> {
title = R.string.error_http_429_title
message = R.string.error_http_429_message
Expand Down
8 changes: 8 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1758,4 +1758,12 @@
<!-- 2023-07-05 -->
<string name="accessibility_subtitle_has_selftext_withperiod">Has self text.</string>

<!-- 2023-07-06 -->
<string name="error_403_quarantined_sr_title">Quarantined subreddit</string>
<string name="error_403_quarantined_sr_message">This subreddit has been quarantined. To access it, you must opt-in on reddit.com.</string>
<string name="error_403_premiumonly_sr_title">Premium-only subreddit</string>
<string name="error_403_premiumonly_sr_message">This subreddit only allows Reddit Premium members to visit.</string>
<string name="error_404_banned_sr_title">Banned subreddit</string>
<string name="error_404_banned_sr_message">This subreddit has been banned.</string>

</resources>

0 comments on commit 72fb4af

Please sign in to comment.