46 lines
1.1 KiB
Dart
46 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flustars_flutter3/flustars_flutter3.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get_connect/http/src/request/request.dart';
|
|
import 'package:dreampad/app/shared/constants/constants.dart';
|
|
|
|
FutureOr<dynamic> responseInterceptor(
|
|
Request request, Response response) async {
|
|
SmartDialog.dismiss(status: SmartStatus.loading);
|
|
|
|
if (handleErrorStatus(response)) {
|
|
return Response(
|
|
headers: response.headers,
|
|
request: request,
|
|
statusCode: response.statusCode,
|
|
body: null,
|
|
);
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
bool handleErrorStatus(Response response) {
|
|
late bool hasError = false;
|
|
switch (response.statusCode) {
|
|
case 302:
|
|
case 404:
|
|
case 500:
|
|
case 504:
|
|
case 401:
|
|
SpUtil.remove(Constant.accessToken);
|
|
SpUtil.remove(Constant.account);
|
|
SpUtil.remove(Constant.password);
|
|
break;
|
|
case 400:
|
|
case 403:
|
|
hasError = true;
|
|
SmartDialog.showToast('服务异常,请稍后重试');
|
|
break;
|
|
default:
|
|
}
|
|
return hasError;
|
|
}
|