diff --git a/lib/utils/errors.js b/lib/utils/errors.js --- a/lib/utils/errors.js +++ b/lib/utils/errors.js @@ -1,7 +1,5 @@ // @flow -import copyError from 'utils-copy-error'; - import type { PlatformDetails } from '../types/device-types.js'; import type { ServerSocketMessageType } from '../types/socket-types.js'; @@ -52,6 +50,17 @@ } } +class SendMessageError extends ExtendableError { + localID: ?string; + threadID: string; + + constructor(error: string, localID: ?string, threadID: string) { + super(error); + this.localID = localID; + this.threadID = threadID; + } +} + function getMessageForException(e: mixed): ?string { if (typeof e === 'string') { return e; @@ -66,16 +75,12 @@ return undefined; } -function cloneError(e: E): E { - return copyError(e); -} - export { ExtendableError, ServerError, FetchTimeout, getMessageForException, - cloneError, SocketOffline, SocketTimeout, + SendMessageError, }; diff --git a/native/chat/reaction-message-utils.js b/native/chat/reaction-message-utils.js --- a/native/chat/reaction-message-utils.js +++ b/native/chat/reaction-message-utils.js @@ -23,7 +23,7 @@ thickThreadTypes, threadTypeIsThick, } from 'lib/types/thread-types-enum.js'; -import { cloneError } from 'lib/utils/errors.js'; +import { SendMessageError, getMessageForException } from 'lib/utils/errors.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -115,10 +115,11 @@ }, ); - const copy = cloneError(e); - copy.localID = localID; - copy.threadID = threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + localID, + threadID, + ); } })(); diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -92,7 +92,7 @@ type NewThickThreadRequest, } from 'lib/types/thread-types.js'; import { getConfig } from 'lib/utils/config.js'; -import { cloneError, getMessageForException } from 'lib/utils/errors.js'; +import { getMessageForException, SendMessageError } from 'lib/utils/errors.js'; import { values } from 'lib/utils/objects.js'; import { type DispatchActionPromise, @@ -358,12 +358,14 @@ const result = await threadCreationPromise; newThreadID = result.threadID; } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; + const payload = new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); this.props.dispatch({ type: sendMultimediaMessageActionTypes.failed, - payload: copy, + payload, error: true, }); return; @@ -403,10 +405,11 @@ this.pendingSidebarCreationMessageLocalIDs.delete(localID); return result; } catch (e) { - const copy = cloneError(e); - copy.localID = localID; - copy.threadID = threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + localID, + threadID, + ); } } @@ -516,12 +519,14 @@ try { threadCreationResult = await this.startThreadCreation(threadInfo); } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; + const payload = new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); this.props.dispatch({ type: sendTextMessageActionTypes.failed, - payload: copy, + payload, error: true, }); return; @@ -585,6 +590,8 @@ parentThreadInfo: ?ThreadInfo, ): Promise { try { + console.log('sendTextMessageAction'); + if (!threadTypeIsThick(threadInfo.type)) { await this.props.textMessageCreationSideEffectsFunc( messageInfo, @@ -615,10 +622,11 @@ this.pendingSidebarCreationMessageLocalIDs.delete(localID); return result; } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); } } diff --git a/web/chat/reaction-message-utils.js b/web/chat/reaction-message-utils.js --- a/web/chat/reaction-message-utils.js +++ b/web/chat/reaction-message-utils.js @@ -24,7 +24,7 @@ thickThreadTypes, threadTypeIsThick, } from 'lib/types/thread-types-enum.js'; -import { cloneError } from 'lib/utils/errors.js'; +import { SendMessageError, getMessageForException } from 'lib/utils/errors.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import Alert from '../modals/alert.react.js'; @@ -118,10 +118,11 @@ , ); - const copy = cloneError(e); - copy.localID = localID; - copy.threadID = threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + localID, + threadID, + ); } })(); diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js --- a/web/input/input-state-container.react.js +++ b/web/input/input-state-container.react.js @@ -95,7 +95,7 @@ makeBlobServiceEndpointURL, } from 'lib/utils/blob-service.js'; import { getConfig } from 'lib/utils/config.js'; -import { cloneError, getMessageForException } from 'lib/utils/errors.js'; +import { getMessageForException, SendMessageError } from 'lib/utils/errors.js'; import { type DispatchActionPromise, useDispatchActionPromise, @@ -493,12 +493,14 @@ const result = await threadCreationPromise; newThreadID = result.threadID; } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; + const payload = new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); this.props.dispatch({ type: sendMultimediaMessageActionTypes.failed, - payload: copy, + payload, error: true, }); return; @@ -586,10 +588,11 @@ }); return result; } catch (e) { - const copy = cloneError(e); - copy.localID = localID; - copy.threadID = threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + localID, + threadID, + ); } } @@ -1353,12 +1356,14 @@ try { threadCreationResult = await this.startThreadCreation(threadInfo); } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; + const payload = new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); this.props.dispatch({ type: sendTextMessageActionTypes.failed, - payload: copy, + payload, error: true, }); return; @@ -1425,10 +1430,11 @@ this.pendingSidebarCreationMessageLocalIDs.delete(localID); return result; } catch (e) { - const copy = cloneError(e); - copy.localID = messageInfo.localID; - copy.threadID = messageInfo.threadID; - throw copy; + throw new SendMessageError( + getMessageForException(e) ?? '', + messageInfo.localID, + messageInfo.threadID, + ); } }