1 import { c } from 'ttag';
3 import type { EventComponentIdentifiers } from '@proton/shared/lib/calendar/icsSurgery/interface';
5 export enum IMPORT_EVENT_ERROR_TYPE {
15 UNEXPECTED_FLOATING_TIME,
19 DTSTART_OUT_OF_BOUNDS,
22 X_WR_TIMEZONE_UNSUPPORTED,
26 SINGLE_EDIT_UNSUPPORTED,
27 NOTIFICATION_OUT_OF_BOUNDS,
35 const getErrorMessage = (errorType: IMPORT_EVENT_ERROR_TYPE, externalError?: Error) => {
36 if (errorType === IMPORT_EVENT_ERROR_TYPE.NO_OCCURRENCES) {
37 return c('Error importing event').t`Recurring event has no occurrences`;
39 if (errorType === IMPORT_EVENT_ERROR_TYPE.WRONG_FORMAT) {
40 return c('Error importing event').t`Component with wrong format`;
42 if (errorType === IMPORT_EVENT_ERROR_TYPE.NON_GREGORIAN) {
43 return c('Error importing event').t`Non-Gregorian`;
45 if (errorType === IMPORT_EVENT_ERROR_TYPE.TODO_FORMAT) {
46 return c('Error importing event').t`To-do entry`;
48 if (errorType === IMPORT_EVENT_ERROR_TYPE.JOURNAL_FORMAT) {
49 return c('Error importing event').t`Journal entry`;
51 if (errorType === IMPORT_EVENT_ERROR_TYPE.FREEBUSY_FORMAT) {
52 return c('Error importing event').t`Free-busy time information`;
54 if (errorType === IMPORT_EVENT_ERROR_TYPE.TIMEZONE_FORMAT) {
55 return c('Error importing event').t`Custom time zone`;
57 if (errorType === IMPORT_EVENT_ERROR_TYPE.TIMEZONE_IGNORE) {
58 return 'Time zone component ignored';
60 if (errorType === IMPORT_EVENT_ERROR_TYPE.VEVENT_INVALID) {
61 return c('Error importing event').t`Invalid event`;
63 if (errorType === IMPORT_EVENT_ERROR_TYPE.VEVENT_UNSUPPORTED) {
64 return c('Error importing event').t`Unsupported event`;
66 if (errorType === IMPORT_EVENT_ERROR_TYPE.ALLDAY_INCONSISTENCY) {
67 return c('Error importing event').t`Malformed all-day event`;
69 if (errorType === IMPORT_EVENT_ERROR_TYPE.DTSTART_MISSING) {
70 return c('Error importing event').t`Missing start time`;
72 if (errorType === IMPORT_EVENT_ERROR_TYPE.DTSTART_MALFORMED) {
73 return c('Error importing event').t`Malformed start time`;
75 if (errorType === IMPORT_EVENT_ERROR_TYPE.UNEXPECTED_FLOATING_TIME) {
76 return c('Error importing event').t`Floating times not supported`;
78 if (errorType === IMPORT_EVENT_ERROR_TYPE.DTSTART_OUT_OF_BOUNDS) {
79 return c('Error importing event').t`Start time out of bounds`;
81 if (errorType === IMPORT_EVENT_ERROR_TYPE.DTEND_MALFORMED) {
82 return c('Error importing event').t`Malformed end time`;
84 if (errorType === IMPORT_EVENT_ERROR_TYPE.DTEND_OUT_OF_BOUNDS) {
85 return c('Error importing event').t`End time out of bounds`;
87 if (errorType === IMPORT_EVENT_ERROR_TYPE.X_WR_TIMEZONE_UNSUPPORTED) {
88 return c('Error importing event').t`Calendar time zone not supported`;
90 if (errorType === IMPORT_EVENT_ERROR_TYPE.TZID_UNSUPPORTED) {
91 return c('Error importing event').t`Time zone not supported`;
93 if (errorType === IMPORT_EVENT_ERROR_TYPE.RRULE_MALFORMED) {
94 return c('Error importing event').t`Malformed recurring event`;
96 if (errorType === IMPORT_EVENT_ERROR_TYPE.RRULE_UNSUPPORTED) {
97 return c('Error importing event').t`Recurring rule not supported`;
99 if (errorType === IMPORT_EVENT_ERROR_TYPE.SINGLE_EDIT_UNSUPPORTED) {
100 return c('Error importing event').t`Edited event not supported`;
102 if (errorType === IMPORT_EVENT_ERROR_TYPE.NOTIFICATION_OUT_OF_BOUNDS) {
103 return c('Error importing event').t`Notification out of bounds`;
105 if (errorType === IMPORT_EVENT_ERROR_TYPE.VALIDATION_ERROR) {
106 return c('Error importing event').t`Event validation failed`;
108 if (errorType === IMPORT_EVENT_ERROR_TYPE.ENCRYPTION_ERROR) {
109 return c('Error importing event').t`Encryption failed`;
111 if (errorType === IMPORT_EVENT_ERROR_TYPE.PARENT_EVENT_MISSING) {
112 return c('Error importing event').t`Original recurring event could not be found`;
114 if (errorType === IMPORT_EVENT_ERROR_TYPE.EXTERNAL_ERROR) {
115 return externalError?.message || '';
120 export class ImportEventError extends Error {
121 componentIdentifiers: EventComponentIdentifiers;
123 type: IMPORT_EVENT_ERROR_TYPE;
125 externalError?: Error;
129 componentIdentifiers,
132 errorType: IMPORT_EVENT_ERROR_TYPE;
133 componentIdentifiers: EventComponentIdentifiers;
134 externalError?: Error;
136 super(getErrorMessage(errorType, externalError));
137 this.type = errorType;
138 this.componentIdentifiers = componentIdentifiers;
139 this.externalError = externalError;
140 Object.setPrototypeOf(this, ImportEventError.prototype);