fixed error handling
This commit is contained in:
parent
9c58d22bad
commit
7fab4fe6d3
@ -552,7 +552,7 @@ public interface Connection {
|
||||
* @param mediaUpdate inputstream with MIME type of the media
|
||||
* @return media ID
|
||||
*/
|
||||
long updateMedia(MediaStatus mediaUpdate) throws ConnectionException, InterruptedException;
|
||||
long updateMedia(MediaStatus mediaUpdate) throws ConnectionException;
|
||||
|
||||
/**
|
||||
* create Web push subscription
|
||||
|
@ -66,7 +66,6 @@ import org.nuclearfog.twidda.model.lists.Users;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
@ -1170,7 +1169,7 @@ public class Mastodon implements Connection {
|
||||
|
||||
|
||||
@Override
|
||||
public long updateMedia(MediaStatus mediaUpdate) throws MastodonException, InterruptedException {
|
||||
public long updateMedia(MediaStatus mediaUpdate) throws MastodonException {
|
||||
try {
|
||||
List<String> params = new ArrayList<>();
|
||||
if (!mediaUpdate.getDescription().isEmpty())
|
||||
@ -1196,9 +1195,7 @@ public class Mastodon implements Connection {
|
||||
}
|
||||
}
|
||||
throw new MastodonException(response);
|
||||
} catch (InterruptedIOException e) {
|
||||
throw new InterruptedException();
|
||||
} catch (IOException | JSONException | NumberFormatException e) {
|
||||
} catch (IOException | JSONException | NumberFormatException | InterruptedException e) {
|
||||
throw new MastodonException(e);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ import org.nuclearfog.twidda.BuildConfig;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import okhttp3.Response;
|
||||
@ -35,9 +37,9 @@ public class MastodonException extends ConnectionException {
|
||||
super(e);
|
||||
if (e instanceof JSONException) {
|
||||
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;
|
||||
} else if (getCause() instanceof InterruptedException) {
|
||||
} else if (getCause() instanceof InterruptedException || e instanceof InterruptedIOException) {
|
||||
errorCode = INTERRUPTED;
|
||||
}
|
||||
}
|
||||
|
@ -63,11 +63,9 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
||||
try {
|
||||
Result result = doInBackground(parameter);
|
||||
onPostExecute(result, callbackReference);
|
||||
} catch (InterruptedException e) {
|
||||
// caused by user interaction. No need to handle exception.
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException exception) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace();
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,7 +118,7 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
||||
* @return result of the background task
|
||||
*/
|
||||
@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
|
||||
|
@ -35,7 +35,7 @@ public class StatusUpdater extends AsyncExecutor<StatusUpdate, StatusUpdater.Res
|
||||
|
||||
|
||||
@Override
|
||||
protected Result doInBackground(@NonNull StatusUpdate update) throws InterruptedException {
|
||||
protected Result doInBackground(@NonNull StatusUpdate update) {
|
||||
try {
|
||||
// upload media first
|
||||
List<Long> mediaIds = new LinkedList<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user