captchanojs2: use the parse exception everywhere

does this by adding a constructor to the exception class, to allow
linking a cause-throwable.
reduce some catches from throwable to exception.
dev
Floens 6 years ago
parent aa27d1c3cb
commit 1ea9810826
  1. 41
      Clover/app/src/main/java/org/floens/chan/ui/captcha/v2/CaptchaNoJsHtmlParser.java
  2. 1
      Clover/app/src/main/java/org/floens/chan/ui/captcha/v2/CaptchaNoJsLayoutV2.java
  3. 2
      Clover/app/src/main/java/org/floens/chan/ui/captcha/v2/CaptchaNoJsPresenterV2.java

@ -25,7 +25,6 @@ import android.support.v4.util.Pair;
import org.floens.chan.utils.BackgroundUtils; import org.floens.chan.utils.BackgroundUtils;
import org.floens.chan.utils.IOUtils; import org.floens.chan.utils.IOUtils;
import org.floens.chan.utils.Logger;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -111,9 +110,8 @@ public class CaptchaNoJsHtmlParser {
try { try {
token = matcher.group(1); token = matcher.group(1);
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Could not parse verification token", error); throw new CaptchaNoJsV2ParsingError("Could not parse verification token", error);
throw error;
} }
if (token == null || token.isEmpty()) { if (token == null || token.isEmpty()) {
@ -154,13 +152,8 @@ public class CaptchaNoJsHtmlParser {
// could not find it // could not find it
captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1);
} }
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Error while trying to parse challenge title", error); throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error);
throw error;
}
if (captchaTitle == null) {
throw new CaptchaNoJsV2ParsingError("challengeTitle is null");
} }
if (captchaTitle.isEmpty()) { if (captchaTitle.isEmpty()) {
@ -184,9 +177,8 @@ public class CaptchaNoJsHtmlParser {
try { try {
challengeImageUrl = matcher.group(1); challengeImageUrl = matcher.group(1);
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Error while trying to parse challenge image url", error); throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge image url", error);
throw error;
} }
if (challengeImageUrl == null) { if (challengeImageUrl == null) {
@ -253,9 +245,8 @@ public class CaptchaNoJsHtmlParser {
try { try {
cParameter = matcher.group(1); cParameter = matcher.group(1);
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Error while trying to parse c parameter", error); throw new CaptchaNoJsV2ParsingError("Error while trying to parse c parameter", error);
throw error;
} }
if (cParameter == null) { if (cParameter == null) {
@ -281,9 +272,8 @@ public class CaptchaNoJsHtmlParser {
try { try {
Integer checkboxId = Integer.parseInt(matcher.group(1)); Integer checkboxId = Integer.parseInt(matcher.group(1));
checkboxesSet.add(checkboxId); checkboxesSet.add(checkboxId);
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Error while trying to parse checkbox with id (" + index + ")", error); throw new CaptchaNoJsV2ParsingError("Error while trying to parse checkbox with id (" + index + ")", error);
throw error;
} }
++index; ++index;
@ -297,9 +287,8 @@ public class CaptchaNoJsHtmlParser {
try { try {
captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size()); captchaType = CaptchaInfo.CaptchaType.fromCheckboxesCount(checkboxesSet.size());
} catch (Throwable error) { } catch (Exception error) {
Logger.e(TAG, "Error while trying to parse captcha type", error); throw new CaptchaNoJsV2ParsingError("Error while trying to parse captcha type", error);
throw error;
} }
if (captchaType == CaptchaInfo.CaptchaType.Unknown) { if (captchaType == CaptchaInfo.CaptchaType.Unknown) {
@ -383,7 +372,7 @@ public class CaptchaNoJsHtmlParser {
} }
return resultImages; return resultImages;
} catch (Throwable error) { } catch (Exception error) {
for (Bitmap bitmap : resultImages) { for (Bitmap bitmap : resultImages) {
if (!bitmap.isRecycled()) { if (!bitmap.isRecycled()) {
bitmap.recycle(); bitmap.recycle();
@ -403,5 +392,9 @@ public class CaptchaNoJsHtmlParser {
public CaptchaNoJsV2ParsingError(String message) { public CaptchaNoJsV2ParsingError(String message) {
super(message); super(message);
} }
public CaptchaNoJsV2ParsingError(String message, Throwable cause) {
super(message, cause);
}
} }
} }

@ -240,6 +240,7 @@ public class CaptchaNoJsLayoutV2 extends FrameLayout
captchaVerifyButton.setEnabled(true); captchaVerifyButton.setEnabled(true);
} catch (Throwable error) { } catch (Throwable error) {
Logger.e(TAG, "renderCaptchaWindow", error);
if (callback != null) { if (callback != null) {
callback.onFallbackToV1CaptchaView(); callback.onFallbackToV1CaptchaView();
} }

@ -320,7 +320,7 @@ public class CaptchaNoJsPresenterV2 {
return captchaInfo; return captchaInfo;
} }
} catch (Throwable e) { } catch (Exception e) {
Logger.e(TAG, "Error while trying to parse captcha html data", e); Logger.e(TAG, "Error while trying to parse captcha html data", e);
if (callbacks != null) { if (callbacks != null) {

Loading…
Cancel
Save