Skip to content

Commit 6d230e1

Browse files
committed
Improve Error Handling, decouple Providers file
1 parent 1a95605 commit 6d230e1

File tree

133 files changed

+764
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+764
-484
lines changed

ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ PODS:
99
- Firebase/Crashlytics (10.18.0):
1010
- Firebase/CoreOnly
1111
- FirebaseCrashlytics (~> 10.18.0)
12-
- firebase_core (2.24.0):
12+
- firebase_core (2.24.2):
1313
- Firebase/CoreOnly (= 10.18.0)
1414
- Flutter
15-
- firebase_crashlytics (3.4.6):
15+
- firebase_crashlytics (3.4.8):
1616
- Firebase/Crashlytics (= 10.18.0)
1717
- firebase_core
1818
- Flutter
@@ -203,8 +203,8 @@ SPEC CHECKSUMS:
203203
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
204204
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
205205
Firebase: 414ad272f8d02dfbf12662a9d43f4bba9bec2a06
206-
firebase_core: f802c5c1f6caff9b8d38b591a36e7b25f8878936
207-
firebase_crashlytics: 0db78a5b6badc630f21a833d0c9ab20ab5d81948
206+
firebase_core: 0af4a2b24f62071f9bf283691c0ee41556dcb3f5
207+
firebase_crashlytics: 55714f63ae0973c54b3a721c451ae5f815086c1f
208208
FirebaseCore: 2322423314d92f946219c8791674d2f3345b598f
209209
FirebaseCoreExtension: c08d14c7b22e07994e876d837e6f58642f340087
210210
FirebaseCoreInternal: 8eb002e564b533bdcf1ba011f33f2b5c10e2ed4a

lib/authentication_router.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:campus_flutter/loginComponent/viewModels/login_viewmodel.dart';
22
import 'package:campus_flutter/loginComponent/views/login_view.dart';
33
import 'package:campus_flutter/navigation.dart';
4-
import 'package:campus_flutter/providers_get_it.dart';
4+
import 'package:campus_flutter/settingsComponent/viewModels/user_preferences_viewmodel.dart';
55
import 'package:flutter/material.dart';
66
import 'package:flutter_native_splash/flutter_native_splash.dart';
77
import 'package:flutter_riverpod/flutter_riverpod.dart';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
class CampusException implements Error {
3+
4+
}
5+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
2+
import 'package:campus_flutter/base/errorHandling/error_handling_view.dart';
3+
import 'package:campus_flutter/base/extensions/custom_exception.dart';
4+
import 'package:flutter/material.dart';
5+
6+
class CustomExceptionRouter extends StatelessWidget with ErrorHandlingView {
7+
CustomExceptionRouter({
8+
super.key,
9+
required this.customException,
10+
required ErrorHandlingViewType errorHandlingViewType,
11+
Future<dynamic> Function(bool)? retry,
12+
Color? titleColor,
13+
Color? bodyColor,
14+
}) {
15+
this.errorHandlingViewType = errorHandlingViewType;
16+
this.retry = retry;
17+
this.titleColor = titleColor;
18+
this.bodyColor = bodyColor;
19+
}
20+
21+
final CustomException customException;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
return exceptionMessage(context, customException.message, null);
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
2+
import 'package:campus_flutter/base/errorHandling/error_handling_view.dart';
3+
import 'package:campus_flutter/base/extensions/context.dart';
4+
import 'package:flutter/material.dart';
5+
6+
class DefaultErrorRouter extends StatelessWidget with ErrorHandlingView {
7+
DefaultErrorRouter({
8+
super.key,
9+
required this.exception,
10+
required ErrorHandlingViewType errorHandlingViewType,
11+
Future<dynamic> Function(bool)? retry,
12+
Color? titleColor,
13+
Color? bodyColor,
14+
}) {
15+
this.errorHandlingViewType = errorHandlingViewType;
16+
this.retry = retry;
17+
this.titleColor = titleColor;
18+
this.bodyColor = bodyColor;
19+
}
20+
21+
final Object exception;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
return exceptionMessage(
26+
context,
27+
context.localizations.unknownError,
28+
context.localizations.pleaseReport,
29+
);
30+
}
31+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
2+
import 'package:campus_flutter/base/errorHandling/error_handling_view.dart';
3+
import 'package:campus_flutter/base/extensions/context.dart';
4+
import 'package:dio/dio.dart';
5+
import 'package:flutter/material.dart';
6+
7+
class DioExceptionRouter extends StatelessWidget with ErrorHandlingView {
8+
DioExceptionRouter({
9+
super.key,
10+
required this.dioException,
11+
required ErrorHandlingViewType errorHandlingViewType,
12+
Future<dynamic> Function(bool)? retry,
13+
Color? titleColor,
14+
Color? bodyColor,
15+
}) {
16+
this.errorHandlingViewType = errorHandlingViewType;
17+
this.retry = retry;
18+
this.titleColor = titleColor;
19+
this.bodyColor = bodyColor;
20+
}
21+
22+
final DioException dioException;
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
switch (dioException.type) {
27+
case DioExceptionType.badResponse:
28+
return exceptionMessage(
29+
context,
30+
context.localizations.badResponse,
31+
context.localizations.pleaseTryAgain,
32+
);
33+
case DioExceptionType.connectionError:
34+
return exceptionMessage(
35+
context,
36+
context.localizations.connectionError,
37+
context.localizations.makeSureInternetConnection,
38+
);
39+
case DioExceptionType.cancel:
40+
return exceptionMessage(
41+
context,
42+
context.localizations.requestCancelled,
43+
context.localizations.pleaseReport,
44+
);
45+
case DioExceptionType.connectionTimeout:
46+
case DioExceptionType.sendTimeout:
47+
case DioExceptionType.receiveTimeout:
48+
return exceptionMessage(
49+
context,
50+
context.localizations.connectionTimeout,
51+
context.localizations.makeSureInternetConnection,
52+
);
53+
default:
54+
if (dioException.error.toString().contains("SocketException")) {
55+
return exceptionMessage(
56+
context,
57+
context.localizations.connectionError,
58+
context.localizations.makeSureInternetConnection,
59+
);
60+
} else {
61+
return exceptionMessage(
62+
context,
63+
context.localizations.unknownError,
64+
context.localizations.pleaseReport,
65+
);
66+
}
67+
}
68+
}
69+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
2+
import 'package:campus_flutter/base/errorHandling/custom_exception_router.dart';
3+
import 'package:campus_flutter/base/errorHandling/default_error_router.dart';
4+
import 'package:campus_flutter/base/errorHandling/dio_exception_router.dart';
5+
import 'package:campus_flutter/base/errorHandling/search_exception_router.dart';
6+
import 'package:campus_flutter/base/errorHandling/tum_online_api_exception_router.dart';
7+
import 'package:campus_flutter/base/errorHandling/type_error_router.dart';
8+
import 'package:campus_flutter/base/extensions/custom_exception.dart';
9+
import 'package:campus_flutter/base/networking/apis/tumOnlineApi/tum_online_api_exception.dart';
10+
import 'package:campus_flutter/loginComponent/viewModels/login_viewmodel.dart';
11+
import 'package:campus_flutter/searchComponent/model/search_exception.dart';
12+
import 'package:dio/dio.dart';
13+
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
14+
import 'package:flutter/material.dart';
15+
import 'package:flutter_riverpod/flutter_riverpod.dart';
16+
17+
class ErrorHandlingRouter extends ConsumerWidget {
18+
const ErrorHandlingRouter({
19+
super.key,
20+
required this.error,
21+
required this.errorHandlingViewType,
22+
this.retry,
23+
this.titleColor,
24+
this.bodyColor,
25+
});
26+
27+
final Object error;
28+
final ErrorHandlingViewType errorHandlingViewType;
29+
final Future<dynamic> Function(bool)? retry;
30+
final Color? titleColor;
31+
final Color? bodyColor;
32+
33+
@override
34+
Widget build(BuildContext context, WidgetRef ref) {
35+
switch (error) {
36+
case DioException dioException:
37+
FirebaseCrashlytics.instance.recordFlutterFatalError(
38+
FlutterErrorDetails(
39+
exception: dioException,
40+
stack: dioException.stackTrace,
41+
),
42+
);
43+
return DioExceptionRouter(
44+
dioException: dioException,
45+
errorHandlingViewType: errorHandlingViewType,
46+
retry: retry,
47+
titleColor: titleColor,
48+
bodyColor: bodyColor,
49+
);
50+
case TumOnlineApiException tumOnlineApiException:
51+
if (ref.read(loginViewModel).credentials.value != Credentials.tumId &&
52+
tumOnlineApiException.tumOnlineApiExceptionType ==
53+
TumOnlineApiExceptionInvalidToken) {
54+
FirebaseCrashlytics.instance.recordFlutterFatalError(
55+
FlutterErrorDetails(
56+
exception: tumOnlineApiException,
57+
stack: StackTrace.current,
58+
),
59+
);
60+
}
61+
return TumOnlineApiExceptionRouter(
62+
tumOnlineApiException: tumOnlineApiException,
63+
errorHandlingViewType: errorHandlingViewType,
64+
retry: retry,
65+
titleColor: titleColor,
66+
bodyColor: bodyColor,
67+
);
68+
case SearchException searchException:
69+
FirebaseCrashlytics.instance.recordFlutterFatalError(
70+
FlutterErrorDetails(
71+
exception: searchException,
72+
),
73+
);
74+
return SearchExceptionRouter(
75+
searchException: searchException,
76+
errorHandlingViewType: errorHandlingViewType,
77+
retry: retry,
78+
titleColor: titleColor,
79+
bodyColor: bodyColor,
80+
);
81+
case CustomException customException:
82+
FirebaseCrashlytics.instance.recordFlutterFatalError(
83+
FlutterErrorDetails(
84+
exception: customException,
85+
),
86+
);
87+
return CustomExceptionRouter(
88+
customException: customException,
89+
errorHandlingViewType: errorHandlingViewType,
90+
retry: retry,
91+
titleColor: titleColor,
92+
bodyColor: bodyColor,
93+
);
94+
case TypeError typeError:
95+
FirebaseCrashlytics.instance.recordFlutterFatalError(
96+
FlutterErrorDetails(
97+
exception: typeError,
98+
stack: typeError.stackTrace,
99+
),
100+
);
101+
return TypeErrorRouter(
102+
typeError: typeError,
103+
errorHandlingViewType: errorHandlingViewType,
104+
retry: retry,
105+
titleColor: titleColor,
106+
bodyColor: bodyColor,
107+
);
108+
default:
109+
FirebaseCrashlytics.instance.recordFlutterError(
110+
FlutterErrorDetails(
111+
exception: error,
112+
),
113+
);
114+
return DefaultErrorRouter(
115+
exception: error,
116+
errorHandlingViewType: errorHandlingViewType,
117+
retry: retry,
118+
titleColor: titleColor,
119+
bodyColor: bodyColor,
120+
);
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)