import 'package:dio/dio.dart';
import 'package:netrain_flutter_app/douwen/custom/http/base/HttpCode.dart';
import 'package:netrain_flutter_app/douwen/custom/http/base/IEntity.dart';

import 'ApiException.dart';

class ErrorInterceptor extends Interceptor{

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    IEntity iEntity = IEntity.fromJson(response.data);
    if (HttpCode.SUCCESS != iEntity.code) {
      throw ApiException(iEntity);
    }
    response.data = iEntity;
    return super.onResponse(response, handler);
  }
}