Errors: Associate by conversationId, properly persist to database

This commit is contained in:
Scott Nonnenberg 2020-10-09 08:06:06 -07:00 committed by Josh Perez
parent 523843f30e
commit 913dbd9e7e
1 changed files with 14 additions and 6 deletions

View File

@ -334,7 +334,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const errors = _.reject(allErrors, error =>
Boolean(error.identifier || error.number)
);
const errorsGroupedById = _.groupBy(allErrors, 'number');
const errorsGroupedById = _.groupBy(allErrors, error => {
const identifier = error.identifier || error.number;
if (!identifier) {
return null;
}
return window.ConversationController.getConversationId(identifier);
});
const finalContacts = (conversationIds || []).map(id => {
const errorsForContact = errorsGroupedById[id];
const isOutgoingKeyError = Boolean(
@ -1703,17 +1710,18 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
);
});
errors = errors.map(e => {
if (
e.constructor === Error ||
e.constructor === TypeError ||
e.constructor === ReferenceError
) {
// Note: in our environment, instanceof can be scary, so we have a backup check
// (Node.js vs Browser context).
// We check instanceof second because typescript believes that anything that comes
// through here must be an instance of Error, so e is 'never' after that check.
if ((e.message && e.stack) || e instanceof Error) {
return _.pick(
e,
'name',
'message',
'code',
'number',
'identifier',
'reason'
) as Required<Error>;
}