FjNetException.create constructor
FjNetException.create(
- DioException error
Implementation
factory FjNetException.create(DioException error) {
switch (error.type) {
case DioExceptionType.cancel:
{
return BadRequestException(-1, "请求取消");
}
case DioExceptionType.connectionError:
{
return BadRequestException(-1, "连接超时");
}
case DioExceptionType.sendTimeout:
{
return BadRequestException(-1, "请求超时");
}
case DioExceptionType.receiveTimeout:
{
return BadRequestException(-1, "响应超时");
}
case DioExceptionType.badResponse:
{
return BadRequestException(-1, "请求错误");
}
case DioExceptionType.badCertificate:
{
return BadRequestException(-1, "未认证异常");
}
case DioExceptionType.unknown:
{
try {
int errCode = error.response?.statusCode ?? 404;
switch (errCode) {
case 400:
{
return BadRequestException(errCode, "请求语法错误");
}
case 401:
{
return UnauthorisedException(errCode, "没有权限");
}
case 403:
{
return UnauthorisedException(errCode, "服务器拒绝执行");
}
case 404:
{
return UnauthorisedException(errCode, "无法连接服务器");
}
case 405:
{
return UnauthorisedException(errCode, "请求方法被禁止");
}
case 500:
{
return UnauthorisedException(errCode, "服务器内部错误");
}
case 502:
{
return UnauthorisedException(errCode, "无效的请求");
}
case 503:
{
return UnauthorisedException(errCode, "服务器挂了");
}
case 505:
{
return UnauthorisedException(errCode, "不支持HTTP协议请求");
}
default:
{
return FjNetException(errCode, error.response?.statusMessage ?? "未知错误");
}
}
} on Exception catch (_) {
return FjNetException(-1, "未知错误");
}
}
default:
{
return FjNetException(-1, error.message ?? "");
}
}
}