Dio를 사용하여 api 통신할때 에러 핸들링하는 코드입니다.
이때 interceptor라고 네트워크 통신중에 가로채서 추가적인 작업을 할 수 있도록 도와주는걸 사용하려고 합니다.
var dio = Dio();
// 에러 핸들링 추가
_dio.interceptors.add(
InterceptorsWrapper(
onError: (error, handler) {
if (error.type == DioExceptionType.connectionTimeout || error.type == DioExceptionType.receiveTimeout) {
// 타임아웃 에러 처리
print("타임아웃됨. 에러 처리");
}
handler.next(error);
},
)
)
이때 “DioExceptionType.connectionTimeout” 대신 “DioErrorType.connectionTimeout”를 쓰면 아래와 같은 에러안내 문구를 볼 수 있습니다.
'DioErrorType' is deprecated and shouldn't be used. Use DioExceptionType instead. This will be removed in 6.0.0.
Try replacing the use of the deprecated member with the replacement.
이럴때 안내된 내용처럼 DioErrorType 대신 DioExceptionType을 쓰면 됩니다.