|
|
@ -9,7 +9,6 @@ import com.android.sdk.net.exception.ServerErrorException; |
|
|
|
import com.android.sdk.net.provider.ErrorMessage; |
|
|
|
import com.android.sdk.net.provider.ErrorMessage; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.ConnectException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import retrofit2.HttpException; |
|
|
|
import retrofit2.HttpException; |
|
|
|
import timber.log.Timber; |
|
|
|
import timber.log.Timber; |
|
|
@ -28,28 +27,30 @@ public class ErrorMessageFactory { |
|
|
|
CharSequence message = null; |
|
|
|
CharSequence message = null; |
|
|
|
//SocketTimeoutException android NetworkErrorException extends IOException
|
|
|
|
//SocketTimeoutException android NetworkErrorException extends IOException
|
|
|
|
//1:网络连接错误处理
|
|
|
|
//1:网络连接错误处理
|
|
|
|
if (exception instanceof ConnectException || |
|
|
|
if (exception instanceof IOException || exception instanceof NetworkErrorException) { |
|
|
|
exception instanceof IOException |
|
|
|
|
|
|
|
|| exception instanceof NetworkErrorException) { |
|
|
|
|
|
|
|
message = mErrorMessage.netErrorMessage(exception); |
|
|
|
message = mErrorMessage.netErrorMessage(exception); |
|
|
|
} |
|
|
|
} |
|
|
|
//2:服务器错误处理
|
|
|
|
//2:服务器错误处理
|
|
|
|
else if (exception instanceof ServerErrorException) { |
|
|
|
else if (exception instanceof ServerErrorException) { |
|
|
|
|
|
|
|
|
|
|
|
int errorType = ((ServerErrorException) exception).getErrorType(); |
|
|
|
int errorType = ((ServerErrorException) exception).getErrorType(); |
|
|
|
if (errorType == ServerErrorException.SERVER_DATA_ERROR) { |
|
|
|
if (errorType == ServerErrorException.SERVER_DATA_ERROR) { |
|
|
|
message = mErrorMessage.serverDataErrorMessage(exception); |
|
|
|
message = mErrorMessage.serverDataErrorMessage(exception); |
|
|
|
} else if (errorType == ServerErrorException.UNKNOW_ERROR) { |
|
|
|
} else if (errorType == ServerErrorException.UNKNOW_ERROR) { |
|
|
|
message = mErrorMessage.serverErrorMessage(exception); |
|
|
|
message = mErrorMessage.serverErrorMessage(exception); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//3:响应码非200处理
|
|
|
|
//3:响应码非200处理
|
|
|
|
else if (exception instanceof HttpException) { |
|
|
|
else if (exception instanceof HttpException) { |
|
|
|
|
|
|
|
|
|
|
|
int code = ((HttpException) exception).code(); |
|
|
|
int code = ((HttpException) exception).code(); |
|
|
|
if (code >= 500/*http 500 表示服务器错误*/) { |
|
|
|
if (code >= 500/*http 500 表示服务器错误*/) { |
|
|
|
message = mErrorMessage.serverErrorMessage(exception); |
|
|
|
message = mErrorMessage.serverErrorMessage(exception); |
|
|
|
} else if (code >= 400/*http 400 表示客户端请求出错*/) { |
|
|
|
} else if (code >= 400/*http 400 表示客户端请求出错*/) { |
|
|
|
message = mErrorMessage.clientRequestErrorMessage(exception); |
|
|
|
message = mErrorMessage.clientRequestErrorMessage(exception); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//4:api 错误处理
|
|
|
|
//4:api 错误处理
|
|
|
|
if (exception instanceof ApiErrorException) { |
|
|
|
if (exception instanceof ApiErrorException) { |
|
|
|