|
@@ -9,6 +9,7 @@ import 'package:telnow_mobile_new/src/model/refreshtoken/refresh_token_body.dart
|
|
|
import 'package:telnow_mobile_new/src/model/token/token.dart';
|
|
import 'package:telnow_mobile_new/src/model/token/token.dart';
|
|
|
import 'package:telnow_mobile_new/src/layouts/components/template.dart';
|
|
import 'package:telnow_mobile_new/src/layouts/components/template.dart';
|
|
|
import 'package:telnow_mobile_new/src/storage/sharedpreferences/shared_preferences_manager.dart';
|
|
import 'package:telnow_mobile_new/src/storage/sharedpreferences/shared_preferences_manager.dart';
|
|
|
|
|
+import 'package:telnow_mobile_new/src/utils/ui_service.dart';
|
|
|
import 'package:telnow_mobile_new/src/utils/dio_logging_interceptors.dart';
|
|
import 'package:telnow_mobile_new/src/utils/dio_logging_interceptors.dart';
|
|
|
import 'package:telnow_mobile_new/src/utils/U.dart';
|
|
import 'package:telnow_mobile_new/src/utils/U.dart';
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
@@ -180,7 +181,7 @@ class ApiAuthProvider {
|
|
|
handlingError(context, 2); //error connection
|
|
handlingError(context, 2); //error connection
|
|
|
} else {
|
|
} else {
|
|
|
await Future.delayed(Duration(milliseconds: 200));
|
|
await Future.delayed(Duration(milliseconds: 200));
|
|
|
- return getData(path, params, context, secondCheck: true);
|
|
|
|
|
|
|
+ return getData(path, params, secondCheck: true);
|
|
|
}
|
|
}
|
|
|
//error server
|
|
//error server
|
|
|
} else if (error.response?.statusCode == 401) {
|
|
} else if (error.response?.statusCode == 401) {
|
|
@@ -191,7 +192,7 @@ class ApiAuthProvider {
|
|
|
handlingError(context, 2); //error connection
|
|
handlingError(context, 2); //error connection
|
|
|
} else {
|
|
} else {
|
|
|
await Future.delayed(Duration(milliseconds: 200));
|
|
await Future.delayed(Duration(milliseconds: 200));
|
|
|
- return getData(path, params, context, secondCheck: true);
|
|
|
|
|
|
|
+ return getData(path, params, secondCheck: true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return Future.error(error);
|
|
return Future.error(error);
|
|
@@ -202,7 +203,7 @@ class ApiAuthProvider {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Future getData(String path, var params, BuildContext context, {bool secondCheck = false}) async {
|
|
|
|
|
|
|
+ Future getData(String path, var params, {bool secondCheck = false}) async {
|
|
|
try {
|
|
try {
|
|
|
Response<String> response = await _dio.getUri(
|
|
Response<String> response = await _dio.getUri(
|
|
|
Uri(path: path, queryParameters: params),
|
|
Uri(path: path, queryParameters: params),
|
|
@@ -212,31 +213,28 @@ class ApiAuthProvider {
|
|
|
},
|
|
},
|
|
|
),
|
|
),
|
|
|
);
|
|
);
|
|
|
-// print(response.data);
|
|
|
|
|
return json.decode(response.data!);
|
|
return json.decode(response.data!);
|
|
|
} on DioException catch (error) {
|
|
} on DioException catch (error) {
|
|
|
- // print(error.response!.statusCode);
|
|
|
|
|
- bool isOpen = ModalRoute.of(context)?.isCurrent != true;
|
|
|
|
|
|
|
+ bool isOpen = UIService.isCurrentRouteInactive;
|
|
|
if (error.response == null) {
|
|
if (error.response == null) {
|
|
|
try {
|
|
try {
|
|
|
final result = await InternetAddress.lookup('google.com');
|
|
final result = await InternetAddress.lookup('google.com');
|
|
|
if (!isOpen && result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
|
|
if (!isOpen && result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
|
|
|
- handlingError(context, 1); //error server
|
|
|
|
|
|
|
+ UIService.handlingError(ErrorType.noInternet); //error server
|
|
|
}
|
|
}
|
|
|
} on SocketException catch (_) {
|
|
} on SocketException catch (_) {
|
|
|
- // if(!isOpen) handlingError(context, 0); //no internet
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
} else if (!isOpen && error.response!.statusCode! >= 500) {
|
|
} else if (!isOpen && error.response!.statusCode! >= 500) {
|
|
|
- handlingError(context, 1); //error server
|
|
|
|
|
|
|
+ UIService.handlingError(ErrorType.serverError); //error server
|
|
|
} else if (!isOpen && error.response?.statusCode == 401) {
|
|
} else if (!isOpen && error.response?.statusCode == 401) {
|
|
|
- handlingError(context, 3); //error auth
|
|
|
|
|
|
|
+ UIService.handlingError(ErrorType.invalidAccount); //error auth
|
|
|
} else {
|
|
} else {
|
|
|
if(!isOpen){
|
|
if(!isOpen){
|
|
|
if (secondCheck) {
|
|
if (secondCheck) {
|
|
|
- // print('secondCheck');
|
|
|
|
|
- handlingError(context, 2); //error connection
|
|
|
|
|
|
|
+ UIService.handlingError(ErrorType.connectionError); //error connection
|
|
|
} else {
|
|
} else {
|
|
|
- return getData(path, params, context, secondCheck: true);
|
|
|
|
|
|
|
+ return getData(path, params, secondCheck: true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -244,7 +242,7 @@ class ApiAuthProvider {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Future postData(String path, var params, var data, context) async {
|
|
|
|
|
|
|
+ Future postData(String path, var params, var data) async {
|
|
|
try {
|
|
try {
|
|
|
Response response = await _dio.postUri(
|
|
Response response = await _dio.postUri(
|
|
|
Uri(path: path, queryParameters: params),
|
|
Uri(path: path, queryParameters: params),
|
|
@@ -263,37 +261,50 @@ class ApiAuthProvider {
|
|
|
try {
|
|
try {
|
|
|
final result = await InternetAddress.lookup('google.com');
|
|
final result = await InternetAddress.lookup('google.com');
|
|
|
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
|
|
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
|
|
|
- showError(context, 'errorConnection'.tr());
|
|
|
|
|
|
|
+ UIService.showError('errorConnection'.tr());
|
|
|
|
|
+ // showError(context, 'errorConnection'.tr());
|
|
|
}
|
|
}
|
|
|
} on SocketException catch (_) {
|
|
} on SocketException catch (_) {
|
|
|
- showError(context, 'noInternet'.tr());
|
|
|
|
|
|
|
+ UIService.showError('noInternet'.tr());
|
|
|
|
|
+ // showError(context, 'noInternet'.tr());
|
|
|
}
|
|
}
|
|
|
} else if (error.response!.statusCode! >= 500) {
|
|
} else if (error.response!.statusCode! >= 500) {
|
|
|
- showError(context, 'errorConnection'.tr());
|
|
|
|
|
|
|
+ UIService.showError('errorConnection'.tr());
|
|
|
|
|
+ // showError(context, 'errorConnection'.tr());
|
|
|
} else if (error.response?.statusCode == 401) {
|
|
} else if (error.response?.statusCode == 401) {
|
|
|
- handlingError(context, 3); //error auth
|
|
|
|
|
|
|
+ UIService.handlingError(ErrorType.invalidAccount);
|
|
|
|
|
+ // handlingError(context, 3); //error auth
|
|
|
} else if (error.response?.statusCode == 422) {
|
|
} else if (error.response?.statusCode == 422) {
|
|
|
if(error.response?.data['message'] == 'Worktime did not found'){
|
|
if(error.response?.data['message'] == 'Worktime did not found'){
|
|
|
- showError(context, 'notFoundWorktime'.tr());
|
|
|
|
|
|
|
+ UIService.showError('notFoundWorktime'.tr());
|
|
|
|
|
+ // showError(context, 'notFoundWorktime'.tr());
|
|
|
} else if(error.response?.data['message'] == 'Cant send broadcast message, you have not permission.'){
|
|
} else if(error.response?.data['message'] == 'Cant send broadcast message, you have not permission.'){
|
|
|
- showError(context, 'broadcastPermission'.tr());
|
|
|
|
|
|
|
+ UIService.showError('broadcastPermission'.tr());
|
|
|
|
|
+ // showError(context, 'broadcastPermission'.tr());
|
|
|
} else if(error.response?.data['message'] == 'Cant send broadcast message, you have not permission.'){
|
|
} else if(error.response?.data['message'] == 'Cant send broadcast message, you have not permission.'){
|
|
|
- showError(context, 'broadcastPermission'.tr());
|
|
|
|
|
|
|
+ UIService.showError('broadcastPermission'.tr());
|
|
|
|
|
+ // showError(context, 'broadcastPermission'.tr());
|
|
|
} else if(error.response?.data['message'] == 'request did not match informant rights'){
|
|
} else if(error.response?.data['message'] == 'request did not match informant rights'){
|
|
|
- showError(context, 'idNotMatch'.tr().replaceAll("#ID", data['user_id']));
|
|
|
|
|
|
|
+ UIService.showError('idNotMatch'.tr().replaceAll("#ID", data['user_id']));
|
|
|
|
|
+ // showError(context, 'idNotMatch'.tr().replaceAll("#ID", data['user_id']));
|
|
|
} else if(error.response?.data['message'] == 'Informant user id not found.' ||
|
|
} else if(error.response?.data['message'] == 'Informant user id not found.' ||
|
|
|
error.response?.data['message'] == 'invalid user informant requested'
|
|
error.response?.data['message'] == 'invalid user informant requested'
|
|
|
){
|
|
){
|
|
|
- showError(context, 'idNotFound'.tr());
|
|
|
|
|
|
|
+ UIService.showError('idNotFound'.tr());
|
|
|
|
|
+ // showError(context, 'idNotFound'.tr());
|
|
|
} else if(error.response?.data['message'] == 'You are not registered as receptionist or room attendant.'){
|
|
} else if(error.response?.data['message'] == 'You are not registered as receptionist or room attendant.'){
|
|
|
- showError(context, 'informantNotRegistered'.tr());
|
|
|
|
|
|
|
+ UIService.showError('informantNotRegistered'.tr());
|
|
|
|
|
+ // showError(context, 'informantNotRegistered'.tr());
|
|
|
} else if(error.response?.data['message'] == 'invalid parent ticket'){
|
|
} else if(error.response?.data['message'] == 'invalid parent ticket'){
|
|
|
- showError(context, 'invalidParentTicket'.tr());
|
|
|
|
|
|
|
+ UIService.showError('invalidParentTicket'.tr());
|
|
|
|
|
+ // showError(context, 'invalidParentTicket'.tr());
|
|
|
} else {
|
|
} else {
|
|
|
- showError(context, error.response?.data['message']);
|
|
|
|
|
|
|
+ UIService.showError(error.response?.data['message']);
|
|
|
|
|
+ // showError(context, error.response?.data['message']);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- showError(context, 'errorServer'.tr());
|
|
|
|
|
|
|
+ UIService.showError('errorServer'.tr());
|
|
|
|
|
+ // showError(context, 'errorServer'.tr());
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|