onResponse method
The callback will be executed on success.
If you want to continue the response, call handler.next
.
If you want to complete the response with some custom data directly,
you can resolve a Response
object with handler.resolve
and other
response interceptor(s) will not be executed.
If you want to complete the response with an error message,
you can reject a DioError
object with handler.reject
.
Implementation
@override
onResponse(Response response, ResponseInterceptorHandler handler) async {
try {
if (response.data is String && response.data[0] == '{') {
try {
response.data = jsonDecode(response.data);
} catch (err) {
AppConfig.printLog(err);
}
}
if (response.statusCode == 200 || response.statusCode == 201) {
response.data = ResultData(response.data, true, Code.success,
headers: response.headers);
}
} catch (e) {
AppConfig.printLog(e.toString() + response.requestOptions.path);
response.data = ResultData(response.data, false, response.statusCode,
headers: response.headers);
}
return super.onResponse(response, handler);
}