dreampad/lib/app/api/interceptors/adapter_interceptor.dart

33 lines
995 B
Dart
Raw Normal View History

2023-11-28 10:44:58 +08:00
import 'dart:async';
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/models/models.dart';
FutureOr<dynamic> adapterInterceptor(Request request, Response response) async {
if (response.body != null && response.statusCode == 200) {
BaseResponse result = BaseResponse.fromJson(response.body);
if (result.code == 200 && result.success!) {
return Response(
headers: response.headers,
request: request,
statusCode: response.statusCode,
body: result.data,
);
} else {
if (result.errors != null && result.errors!.isNotEmpty) {
SmartDialog.showToast(result.errors![0].description!);
return Response(
headers: response.headers,
request: request,
statusCode: response.statusCode,
body: null,
);
}
}
}
return response;
}