mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 06:07:57 -06:00
fix: Add custom fields, translations, add app logs to login routes
This commit is contained in:
6
lib/core/bloc/loading_status.dart
Normal file
6
lib/core/bloc/loading_status.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
enum LoadingStatus {
|
||||
initial,
|
||||
loading,
|
||||
loaded,
|
||||
error;
|
||||
}
|
||||
41
lib/core/bloc/my_bloc_observer.dart
Normal file
41
lib/core/bloc/my_bloc_observer.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/core/bloc/transient_error.dart';
|
||||
import 'package:paperless_mobile/core/translation/error_code_localization_mapper.dart';
|
||||
import 'package:paperless_mobile/features/logging/data/logger.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
import 'package:paperless_mobile/routing/navigation_keys.dart';
|
||||
|
||||
class MyBlocObserver extends BlocObserver {
|
||||
@override
|
||||
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
|
||||
if (error is TransientError) {
|
||||
_handleTransientError(bloc, error, stackTrace);
|
||||
}
|
||||
super.onError(bloc, error, stackTrace);
|
||||
}
|
||||
|
||||
void _handleTransientError(
|
||||
BlocBase bloc,
|
||||
TransientError error,
|
||||
StackTrace stackTrace,
|
||||
) {
|
||||
assert(rootNavigatorKey.currentContext != null);
|
||||
final message = switch (error) {
|
||||
TransientPaperlessApiError(code: var code) => translateError(
|
||||
rootNavigatorKey.currentContext!,
|
||||
code,
|
||||
),
|
||||
TransientMessageError(message: var message) => message,
|
||||
};
|
||||
final details = switch (error) {
|
||||
TransientPaperlessApiError(details: var details) => details,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
showSnackBar(
|
||||
rootNavigatorKey.currentContext!,
|
||||
message,
|
||||
details: details,
|
||||
);
|
||||
}
|
||||
}
|
||||
16
lib/core/bloc/transient_error.dart
Normal file
16
lib/core/bloc/transient_error.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
sealed class TransientError extends Error {}
|
||||
|
||||
class TransientPaperlessApiError extends TransientError {
|
||||
final ErrorCode code;
|
||||
final String? details;
|
||||
|
||||
TransientPaperlessApiError({required this.code, this.details});
|
||||
}
|
||||
|
||||
class TransientMessageError extends TransientError {
|
||||
final String message;
|
||||
|
||||
TransientMessageError({required this.message});
|
||||
}
|
||||
Reference in New Issue
Block a user