diff --git a/src/script/conversation/MessageRepository.ts b/src/script/conversation/MessageRepository.ts index a7c0cdf6669..f69d9b9e11c 100644 --- a/src/script/conversation/MessageRepository.ts +++ b/src/script/conversation/MessageRepository.ts @@ -483,19 +483,15 @@ export class MessageRepository { return; } if (state === MessageSendingState.CANCELED) { - throw new ConversationError( - ConversationError.TYPE.DEGRADED_CONVERSATION_CANCELLATION, - ConversationError.MESSAGE.DEGRADED_CONVERSATION_CANCELLATION, - ); + // The user has canceled the upload, no need to do anything else + return; } try { await this.sendAssetRemotedata(conversation, file, id, asImage); const uploadDuration = (Date.now() - uploadStarted) / TIME_IN_MILLIS.SECOND; this.logger.info(`Finished to upload asset for conversation'${conversation.id} in ${uploadDuration}`); } catch (error) { - if (this.isUserCancellationError(error)) { - throw error; - } else if (error instanceof RequestCancellationError) { + if (error instanceof RequestCancellationError) { return; } this.logger.error( @@ -640,14 +636,6 @@ export class MessageRepository { return this.sendAndInjectMessage(payload, conversation); } - private isUserCancellationError(error: any): boolean { - const errorTypes: string[] = [ - ConversationError.TYPE.DEGRADED_CONVERSATION_CANCELLATION, - ConversationError.TYPE.LEGAL_HOLD_CONVERSATION_CANCELLATION, - ]; - return errorTypes.includes(error.type); - } - /** * Will request user permission before sending a message in case the conversation is in a degraded state * @@ -806,6 +794,7 @@ export class MessageRepository { const shouldProceedSending = await injectOptimisticEvent(); if (shouldProceedSending === false) { + this.logger.log('User has canceled sending a message to a degraded conversation.'); return {id: payload.messageId, sentAt: new Date().toISOString(), state: MessageSendingState.CANCELED}; } diff --git a/src/script/error/ConversationError.ts b/src/script/error/ConversationError.ts index 974a24b7dca..92495ed8a4e 100644 --- a/src/script/error/ConversationError.ts +++ b/src/script/error/ConversationError.ts @@ -21,7 +21,6 @@ import {BaseError, BASE_ERROR_TYPE} from './BaseError'; enum CONVERSATION_ERROR_TYPE { CONVERSATION_NOT_FOUND = 'CONVERSATION_NOT_FOUND', - DEGRADED_CONVERSATION_CANCELLATION = 'DEGRADED_CONVERSATION_CANCELLATION', INVALID_PARAMETER = 'INVALID_PARAMETER', LEGAL_HOLD_CONVERSATION_CANCELLATION = 'LEGAL_HOLD_CONVERSATION_CANCELLATION', MESSAGE_NOT_FOUND = 'MESSAGE_NOT_FOUND', @@ -47,7 +46,6 @@ export class ConversationError extends BaseError { static get MESSAGE(): Record { return { CONVERSATION_NOT_FOUND: 'Conversation not found', - DEGRADED_CONVERSATION_CANCELLATION: 'Sending to degraded conversation was canceled by user', INVALID_PARAMETER: 'Invalid parameter passed', LEGAL_HOLD_CONVERSATION_CANCELLATION: 'Sending to legal hold conversation was canceled by user', MESSAGE_NOT_FOUND: 'Message not found in conversation', @@ -66,7 +64,6 @@ export class ConversationError extends BaseError { static get TYPE(): Record { return { CONVERSATION_NOT_FOUND: CONVERSATION_ERROR_TYPE.CONVERSATION_NOT_FOUND, - DEGRADED_CONVERSATION_CANCELLATION: CONVERSATION_ERROR_TYPE.DEGRADED_CONVERSATION_CANCELLATION, INVALID_PARAMETER: CONVERSATION_ERROR_TYPE.INVALID_PARAMETER, LEGAL_HOLD_CONVERSATION_CANCELLATION: CONVERSATION_ERROR_TYPE.LEGAL_HOLD_CONVERSATION_CANCELLATION, MESSAGE_NOT_FOUND: CONVERSATION_ERROR_TYPE.MESSAGE_NOT_FOUND, diff --git a/src/script/ui/WindowHandler.ts b/src/script/ui/WindowHandler.ts index eccf993f8f3..8404f17257c 100644 --- a/src/script/ui/WindowHandler.ts +++ b/src/script/ui/WindowHandler.ts @@ -34,13 +34,6 @@ export class WindowHandler { window.addEventListener('unhandledrejection', (promiseRejectionEvent: any): void | false => { const error = promiseRejectionEvent.reason || {}; - const isDegraded = error.type === ConversationError.TYPE.DEGRADED_CONVERSATION_CANCELLATION; - if (isDegraded) { - this.logger.log('User has canceled sending a message to a degraded conversation.'); - promiseRejectionEvent.preventDefault(); - promiseRejectionEvent.stopPropagation(); - return false; - } const isLegalHoldReject = error.type === ConversationError.TYPE.LEGAL_HOLD_CONVERSATION_CANCELLATION; if (isLegalHoldReject) { this.logger.log('User has canceled sending a message to a conversation under legal hold.');