Line data Source code
1 : import 'options.dart'; 2 : import 'response.dart'; 3 : 4 7 : enum DioErrorType { 5 : /// It occurs when url is opened timeout. 6 6 : CONNECT_TIMEOUT, 7 : 8 : /// It occurs when url is sent timeout. 9 6 : SEND_TIMEOUT, 10 : 11 : ///It occurs when receiving timeout. 12 6 : RECEIVE_TIMEOUT, 13 : 14 : /// When the server response, but with a incorrect status, such as 404, 503... 15 6 : RESPONSE, 16 : 17 : /// When the request is cancelled, dio will throw a error with this type. 18 6 : CANCEL, 19 : 20 : /// Default error type, Some other Error. In this case, you can 21 : /// use the DioError.error if it is not null. 22 6 : DEFAULT, 23 : } 24 : 25 : /// DioError describes the error info when request failed. 26 : class DioError implements Exception { 27 5 : DioError({ 28 : this.request, 29 : this.response, 30 : this.type = DioErrorType.DEFAULT, 31 : this.error, 32 : }); 33 : 34 : /// Request info. 35 : RequestOptions request; 36 : 37 : /// Response info, it may be `null` if the request can't reach to 38 : /// the http server, for example, occurring a dns error, network is not available. 39 : Response response; 40 : 41 : DioErrorType type; 42 : 43 : /// The original error/exception object; It's usually not null when `type` 44 : /// is DioErrorType.DEFAULT 45 : dynamic error; 46 : 47 6 : String get message => (error?.toString() ?? ''); 48 : 49 1 : @override 50 : String toString() { 51 3 : var msg = 'DioError [$type]: $message'; 52 2 : if (error is Error) { 53 0 : msg += '\n${error.stackTrace}'; 54 : } 55 : return msg; 56 : } 57 : }