You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB
Dart

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:dio/dio.dart';
import 'package:http2/http2.dart';
import 'package:isekai_wiki/api/base_api.dart';
import 'package:isekai_wiki/api/mw/mw_api.dart';
class ErrorUtils {
static String getErrorMessage(dynamic err) {
if (err is MWApiEmptyBodyException) {
return "加载的数据为空";
} else if (err is MWApiErrorException) {
return err.info ?? err.code;
} else if (err is HttpResponseException) {
return "服务器错误:${err.statusCode} ${err.statusText}";
} else if (err is TypeError) {
// JSON解析错误
return "服务器返回的数据不正确";
} else if (err is DioError) {
if (err.type == DioErrorType.connectTimeout ||
err.type == DioErrorType.sendTimeout ||
err.type == DioErrorType.receiveTimeout) {
return "链接超时,请重试";
} else if (err.type == DioErrorType.response) {
return "HTTP错误${err.response?.statusCode} ${err.response?.statusMessage}";
} else if (err.type == DioErrorType.other) {
var innerErr = err.error! as Exception;
if (innerErr is StreamTransportException) {
return innerErr.message;
}
}
return err.message;
}
return err.toString();
}
}