mirror of https://github.com/kurisufriend/Clover
Fix issue with the ThreadStatusCell not updating correctly on error status changes. Fix crash on clicking up/down when no thread is loaded. Abstract the volley error to abstract the message needed and if it's a 404.multisite
parent
1510b12766
commit
b9bc730e4f
@ -0,0 +1,64 @@ |
||||
package org.floens.chan.core.exception; |
||||
|
||||
import com.android.volley.AuthFailureError; |
||||
import com.android.volley.NetworkError; |
||||
import com.android.volley.ParseError; |
||||
import com.android.volley.ServerError; |
||||
import com.android.volley.TimeoutError; |
||||
import com.android.volley.VolleyError; |
||||
|
||||
import org.floens.chan.R; |
||||
|
||||
import javax.net.ssl.SSLException; |
||||
|
||||
public class ChanLoaderException extends Exception { |
||||
private VolleyError volleyError; |
||||
|
||||
public ChanLoaderException(VolleyError volleyError) { |
||||
this.volleyError = volleyError; |
||||
} |
||||
|
||||
public ChanLoaderException() { |
||||
} |
||||
|
||||
public ChanLoaderException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
public ChanLoaderException(String message, Throwable cause) { |
||||
super(message, cause); |
||||
} |
||||
|
||||
public ChanLoaderException(Throwable cause) { |
||||
super(cause); |
||||
} |
||||
|
||||
public boolean isNotFound() { |
||||
return volleyError instanceof ServerError && isServerErrorNotFound((ServerError) volleyError); |
||||
} |
||||
|
||||
public int getErrorMessage() { |
||||
int errorMessage; |
||||
if (volleyError.getCause() instanceof SSLException) { |
||||
errorMessage = R.string.thread_load_failed_ssl; |
||||
} else if (volleyError instanceof NetworkError || |
||||
volleyError instanceof TimeoutError || |
||||
volleyError instanceof ParseError || |
||||
volleyError instanceof AuthFailureError) { |
||||
errorMessage = R.string.thread_load_failed_network; |
||||
} else if (volleyError instanceof ServerError) { |
||||
if (isServerErrorNotFound((ServerError) volleyError)) { |
||||
errorMessage = R.string.thread_load_failed_not_found; |
||||
} else { |
||||
errorMessage = R.string.thread_load_failed_server; |
||||
} |
||||
} else { |
||||
errorMessage = R.string.thread_load_failed_parsing; |
||||
} |
||||
return errorMessage; |
||||
} |
||||
|
||||
private boolean isServerErrorNotFound(ServerError serverError) { |
||||
return serverError.networkResponse != null && serverError.networkResponse.statusCode == 404; |
||||
} |
||||
} |
Loading…
Reference in new issue