Skip to content

Commit 8d399ce

Browse files
Use HelperTools' getNSErrorFrom: instead of homegrowing NSError
1 parent d270f1f commit 8d399ce

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

Monal/Classes/MLIQProcessor.m

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ +(void) processErrorIq:(XMPPIQ*) iqNode forAccount:(xmpp*) account
250250
$$class_handler(handleMAMBackscrollingResultInvalidation, $$ID(xmpp*, account), $$ID(MLContact*, contact), $$PROMISE(promise))
251251
DDLogError(@"Got backscrolling mam error for %@", contact.contactJid);
252252
NSString* errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Could not fetch more old chat history for '%@' from the server archive. Please try again.", @""), contact.contactJid];
253-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
254-
[promise reject:error];
253+
[promise reject:[HelperTools getNSErrorFrom:nil withDescription:errorMessage]];
255254
$$
256255

257256
$$class_handler(handleMAMBackscrollingResult, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(MLContact*, contact), $_ID(NSMutableOrderedSet*, historyIdsOfAlreadyRetreivedMessages), $$PROMISE(promise))
@@ -281,15 +280,15 @@ +(void) processErrorIq:(XMPPIQ*) iqNode forAccount:(xmpp*) account
281280
if([iqNode check:@"/<type=error>"] && retrievedBodiesOverall == 0
282281
&& ![iqNode check:@"error/{urn:ietf:params:xml:ns:xmpp-stanzas}item-not-found"])
283282
{
284-
NSString* errorMessage = [HelperTools extractXMPPError:iqNode withDescription:NSLocalizedString(@"Could not fetch more old history for this chat from the server archive. Please try again later.", @"")];
285-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
286-
[promise reject:error];
283+
NSString* errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Could not fetch more old chat history for '%@' from the server archive", @""), contact.contactJid];
284+
[promise reject:[HelperTools getNSErrorFrom:iqNode withDescription:errorMessage]];
287285
}
288286
else
289287
{
290288
if(retrievedBodiesOverall == 0)
291289
{
292-
//if we did not retrieve any body messages we don't need to process metadata sanzas (if any), but signal we reached the end of our archive
290+
//if we did not retrieve any body messages we don't need to process metadata stanzas (if any),
291+
//but signal we reached the end of our archive
293292
DDLogDebug(@"Reached upper end of mam:2 archive");
294293
[promise fulfill:@[]];
295294
return;
@@ -881,8 +880,7 @@ +(BOOL) processRosterWithAccount:(xmpp*) account andIqNode:(XMPPIQ*) iqNode
881880
DDLogError(@"Could not change the password of '%@'", jid);
882881
[SAMKeychain deletePasswordForService:kMonalTmpKeychainName account:uuid];
883882
NSString* errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Could not change the password of '%@'. Please try again.", @""), jid];
884-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
885-
[promise reject:error];
883+
[promise reject:[HelperTools getNSErrorFrom:nil withDescription:errorMessage]];
886884
$$
887885

888886
$$class_handler(handlePasswordChange, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(NSString*, uuid), $$PROMISE(promise))
@@ -891,9 +889,8 @@ +(BOOL) processRosterWithAccount:(xmpp*) account andIqNode:(XMPPIQ*) iqNode
891889
{
892890
DDLogError(@"Changing the password of '%@' returned error: %@", jid, [iqNode findFirst:@"error"]);
893891
[SAMKeychain deletePasswordForService:kMonalTmpKeychainName account:uuid];
894-
NSString* errorMessage = [HelperTools extractXMPPError:iqNode withDescription:[NSString stringWithFormat:NSLocalizedString(@"Could not change the password of '%@'", @""), jid]];
895-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
896-
[promise reject:error];
892+
NSString* errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Could not change the password of '%@'", @""), jid];
893+
[promise reject:[HelperTools getNSErrorFrom:iqNode withDescription:errorMessage]];
897894
}
898895
else
899896
{

Monal/Classes/MLMucProcessor.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,15 +1344,15 @@ -(AnyPromise*) setAffiliation:(NSString*) affiliation ofUser:(NSString*) jid inM
13441344
$$instance_handler(handleAffiliationUpdateResultInvalidation, account.mucProcessor, $$ID(xmpp*, account), $$ID(NSString*, affiliation), $$ID(NSString*, jid), $$ID(NSString*, roomJid), $$PROMISE(promise))
13451345
DDLogError(@"Failed to change affiliation of '%@' in '%@' to '%@'", jid, roomJid, affiliation);
13461346
NSString* errorString = [NSString stringWithFormat:NSLocalizedString(@"Failed to change affiliation of '%@' in '%@' to '%@': please try again", @""), jid, roomJid, affiliation];
1347-
[promise reject:[NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}]];
1347+
[promise reject:[HelperTools getNSErrorFrom:nil withDescription:errorString]];
13481348
$$
13491349

13501350
$$instance_handler(handleAffiliationUpdateResult, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(NSString*, affiliation), $$ID(NSString*, jid), $$ID(NSString*, roomJid), $$PROMISE(promise))
13511351
if([iqNode check:@"/<type=error>"])
13521352
{
13531353
DDLogError(@"Failed to change affiliation of '%@' in '%@' to '%@': %@", jid, roomJid, affiliation, [iqNode findFirst:@"error"]);
13541354
NSString* errorString = [HelperTools extractXMPPError:iqNode withDescription:[NSString stringWithFormat:NSLocalizedString(@"Failed to change affiliation of '%@' in '%@' to '%@'", @""), jid, roomJid, affiliation]];
1355-
[promise reject:[NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}]];
1355+
[promise reject:[HelperTools getNSErrorFrom:iqNode withDescription:errorString]];
13561356
return;
13571357
}
13581358
DDLogInfo(@"Successfully changed affiliation of '%@' in '%@' to '%@'", jid, roomJid, affiliation);
@@ -1410,17 +1410,15 @@ -(AnyPromise*) publishAvatar:(UIImage* _Nullable) image forMuc:(NSString*) room
14101410

14111411
$$instance_handler(handleAvatarPublishResultInvalidation, account.mucProcessor, $$ID(xmpp*, account), $$ID(NSString*, room), $$PROMISE(promise))
14121412
NSString* errorString = [NSString stringWithFormat:NSLocalizedString(@"Failed to publish avatar image for group/channel %@: please try again", @""), room];
1413-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
1414-
[promise reject:error];
1413+
[promise reject:[HelperTools getNSErrorFrom:nil withDescription:errorString]];
14151414
$$
14161415

14171416
$$instance_handler(handleAvatarPublishResult, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$PROMISE(promise))
14181417
if([iqNode check:@"/<type=error>"])
14191418
{
14201419
DDLogError(@"Publishing avatar for muc '%@' returned error: %@", iqNode.fromUser, [iqNode findFirst:@"error"]);
14211420
NSString* errorString = [NSString stringWithFormat:NSLocalizedString(@"Failed to publish avatar image for group/channel %@", @""), iqNode.fromUser];
1422-
NSError* error = [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
1423-
[promise reject:error];
1421+
[promise reject:[HelperTools getNSErrorFrom:iqNode withDescription:errorString]];
14241422
return;
14251423
}
14261424
DDLogInfo(@"Successfully published avatar for muc: %@", iqNode.fromUser);

0 commit comments

Comments
 (0)