-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheventide_exception.dart
More file actions
56 lines (47 loc) · 2.59 KB
/
eventide_exception.dart
File metadata and controls
56 lines (47 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'package:flutter/services.dart';
/// An exception thrown by the Flutter Calendar Connect plugin.
abstract class ETException extends PlatformException {
ETException({required super.code, required super.message, super.details});
}
/// An exception thrown when the user refuses to grant calendar permissions.
final class ETPermissionException extends ETException {
ETPermissionException({required super.message, super.details}) : super(code: 'ACCESS_REFUSED');
}
/// An exception thrown when a calendar/event/reminder is not found.
final class ETNotFoundException extends ETException {
ETNotFoundException({required super.message, super.details}) : super(code: 'NOT_FOUND');
}
/// An exception thrown when the calendar is not editable.
final class ETNotEditableException extends ETException {
ETNotEditableException({required super.message, super.details}) : super(code: 'NOT_EDITABLE');
}
/// An exception thrown when an unknown plugin error occurs.
final class ETGenericException extends ETException {
ETGenericException({required super.message, super.details}) : super(code: 'GENERIC_ERROR');
}
/// An exception thrown when the requested operation is not supported by the platform.
final class ETNotSupportedByPlatform extends ETException {
ETNotSupportedByPlatform({required super.message, super.details}) : super(code: 'NOT_SUPPORTED_BY_PLATFORM');
}
/// An exception thrown when the user cancels event creation in the native platform.
final class ETUserCanceledException extends ETException {
ETUserCanceledException({required super.message, super.details}) : super(code: 'USER_CANCELED');
}
/// An exception thrown when the event creation view cannot be presented.
final class ETPresentationException extends ETException {
ETPresentationException({required super.message, super.details}) : super(code: 'PRESENTATION_ERROR');
}
extension PlatformExceptionToETCalendarException on PlatformException {
/// Converts a [PlatformException] to a [ETException].
ETException toETException() {
return switch (code) {
'ACCESS_REFUSED' => ETPermissionException(message: message, details: details),
'NOT_FOUND' => ETNotFoundException(message: message, details: details),
'NOT_EDITABLE' => ETNotEditableException(message: message, details: details),
'NOT_SUPPORTED_BY_PLATFORM' => ETNotSupportedByPlatform(message: message, details: details),
'USER_CANCELED' => ETUserCanceledException(message: message, details: details),
'PRESENTATION_ERROR' => ETPresentationException(message: message, details: details),
_ => ETGenericException(message: message, details: details),
};
}
}