package com.ewallet.citygo.controller;
import android.content.Context;
import com.android.volley.*;
import com.android.volley.VolleyError;
import com.ewallet.citygo.utils.Utils;
public class VolleyErrorController {
VolleyError volleyError;
Context context;
public VolleyErrorController(Context context,VolleyError volleyError) {
this.volleyError = volleyError;
this.context=context;
}
TimeoutError timeoutError = new TimeoutError();
//AuthFailureError:如果在做一个HTTP的身份验证,可能会发生这个错误。
//NetworkError:Socket关闭,服务器宕机,DNS错误都会产生这个错误。
//NoConnectionError:和NetworkError类似,这个是客户端没有网络连接。
//ParseError:在使用JsonObjectRequest或JsonArrayRequest时,如果接收到的JSON是畸形,会产生异常。
//SERVERERROR:服务器的响应的一个错误,最有可能的4xx或5xx HTTP状态代码。
//TimeoutError:Socket超时,服务器太忙或网络延迟会产生这个异常。默认情况下,Volley的超时时间为2.5秒。如果得到这个错误可以使用RetryPolicy。
public void showMsg() {
if (volleyError instanceof NoConnectionError) {
Utils.alertWithOneButton(context, "連不上伺服器,請開啟網路");
} else if (volleyError instanceof TimeoutError) {
Utils.alertWithOneButton(context, "網路逾時請洽客服");
} else if (volleyError instanceof AuthFailureError) {
Utils.alertWithOneButton(context, "伺服器認證失敗請洽客服");
} else if (volleyError instanceof ServerError) {
Utils.alertWithOneButton(context, "伺服器連線失敗請洽客服");
} else if (volleyError instanceof NetworkError) {
Utils.alertWithOneButton(context, "伺服器網域找不到 請稍後在試");
} else if (volleyError instanceof ParseError) {
Utils.alertWithOneButton(context, "收到不預期的結果請更新版本");
}
}
}
沒有留言:
張貼留言