Errors: Associate by conversationId, properly persist to database
This commit is contained in:
parent
523843f30e
commit
913dbd9e7e
1 changed files with 14 additions and 6 deletions
|
@ -334,7 +334,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
const errors = _.reject(allErrors, error =>
|
const errors = _.reject(allErrors, error =>
|
||||||
Boolean(error.identifier || error.number)
|
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 finalContacts = (conversationIds || []).map(id => {
|
||||||
const errorsForContact = errorsGroupedById[id];
|
const errorsForContact = errorsGroupedById[id];
|
||||||
const isOutgoingKeyError = Boolean(
|
const isOutgoingKeyError = Boolean(
|
||||||
|
@ -1703,17 +1710,18 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
errors = errors.map(e => {
|
errors = errors.map(e => {
|
||||||
if (
|
// Note: in our environment, instanceof can be scary, so we have a backup check
|
||||||
e.constructor === Error ||
|
// (Node.js vs Browser context).
|
||||||
e.constructor === TypeError ||
|
// We check instanceof second because typescript believes that anything that comes
|
||||||
e.constructor === ReferenceError
|
// 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(
|
return _.pick(
|
||||||
e,
|
e,
|
||||||
'name',
|
'name',
|
||||||
'message',
|
'message',
|
||||||
'code',
|
'code',
|
||||||
'number',
|
'number',
|
||||||
|
'identifier',
|
||||||
'reason'
|
'reason'
|
||||||
) as Required<Error>;
|
) as Required<Error>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue