fixed error handling

This commit is contained in:
nuclearfog 2023-10-06 22:35:59 +02:00
parent 9c58d22bad
commit 7fab4fe6d3
No known key found for this signature in database
GPG Key ID: 03488A185C476379
5 changed files with 11 additions and 14 deletions

View File

@ -552,7 +552,7 @@ public interface Connection {
* @param mediaUpdate inputstream with MIME type of the media * @param mediaUpdate inputstream with MIME type of the media
* @return media ID * @return media ID
*/ */
long updateMedia(MediaStatus mediaUpdate) throws ConnectionException, InterruptedException; long updateMedia(MediaStatus mediaUpdate) throws ConnectionException;
/** /**
* create Web push subscription * create Web push subscription

View File

@ -66,7 +66,6 @@ import org.nuclearfog.twidda.model.lists.Users;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InterruptedIOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.KeyPairGenerator; import java.security.KeyPairGenerator;
@ -1170,7 +1169,7 @@ public class Mastodon implements Connection {
@Override @Override
public long updateMedia(MediaStatus mediaUpdate) throws MastodonException, InterruptedException { public long updateMedia(MediaStatus mediaUpdate) throws MastodonException {
try { try {
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
if (!mediaUpdate.getDescription().isEmpty()) if (!mediaUpdate.getDescription().isEmpty())
@ -1196,9 +1195,7 @@ public class Mastodon implements Connection {
} }
} }
throw new MastodonException(response); throw new MastodonException(response);
} catch (InterruptedIOException e) { } catch (IOException | JSONException | NumberFormatException | InterruptedException e) {
throw new InterruptedException();
} catch (IOException | JSONException | NumberFormatException e) {
throw new MastodonException(e); throw new MastodonException(e);
} }
} }

View File

@ -8,7 +8,9 @@ import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.ConnectionException; import org.nuclearfog.twidda.backend.api.ConnectionException;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import okhttp3.Response; import okhttp3.Response;
@ -35,9 +37,9 @@ public class MastodonException extends ConnectionException {
super(e); super(e);
if (e instanceof JSONException) { if (e instanceof JSONException) {
errorCode = JSON_FORMAT; errorCode = JSON_FORMAT;
} else if (e instanceof ConnectException || e instanceof UnknownHostException) { } else if (e instanceof ConnectException || e instanceof UnknownHostException || e instanceof SocketTimeoutException) {
errorCode = NO_CONNECTION; errorCode = NO_CONNECTION;
} else if (getCause() instanceof InterruptedException) { } else if (getCause() instanceof InterruptedException || e instanceof InterruptedIOException) {
errorCode = INTERRUPTED; errorCode = INTERRUPTED;
} }
} }

View File

@ -63,11 +63,9 @@ public abstract class AsyncExecutor<Parameter, Result> {
try { try {
Result result = doInBackground(parameter); Result result = doInBackground(parameter);
onPostExecute(result, callbackReference); onPostExecute(result, callbackReference);
} catch (InterruptedException e) { } catch (RuntimeException exception) {
// caused by user interaction. No need to handle exception.
} catch (Exception e) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
e.printStackTrace(); exception.printStackTrace();
} }
} }
} }
@ -120,7 +118,7 @@ public abstract class AsyncExecutor<Parameter, Result> {
* @return result of the background task * @return result of the background task
*/ */
@WorkerThread @WorkerThread
protected abstract Result doInBackground(@NonNull Parameter param) throws InterruptedException; protected abstract Result doInBackground(@NonNull Parameter param);
/** /**
* Callback used to send task result to main thread * Callback used to send task result to main thread

View File

@ -35,7 +35,7 @@ public class StatusUpdater extends AsyncExecutor<StatusUpdate, StatusUpdater.Res
@Override @Override
protected Result doInBackground(@NonNull StatusUpdate update) throws InterruptedException { protected Result doInBackground(@NonNull StatusUpdate update) {
try { try {
// upload media first // upload media first
List<Long> mediaIds = new LinkedList<>(); List<Long> mediaIds = new LinkedList<>();