IOSAD-148 Sane error handling.

IOSAD-148
Dirk Zimmermann 3 years ago
parent fcb7096a93
commit 270dff98ee
  1. 10
      pEpObjCAdapter/NSError+PEP+Internal.h
  2. 31
      pEpObjCAdapter/NSError+PEP.m

@ -16,15 +16,9 @@
*/
@interface NSError (Internal)
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict;
+ (NSError * _Nullable)errorWithPEPStatus:(PEPStatus)status;
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status;
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict;
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status;
+ (NSError * _Nullable)errorWithPEPStatusInternal:(PEP_STATUS)status;
/**
If the given status indicates an error, tries to set the given error accordingly.

@ -17,8 +17,7 @@ static NSString *s_pEpAdapterDomain = @"security.pEp.ObjCAdapter";
@implementation NSError (Extension)
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
+ (NSError * _Nullable)errorWithPEPStatusInternal:(PEP_STATUS)status
{
switch (status) {
case PEP_STATUS_OK:
@ -30,22 +29,19 @@ static NSString *s_pEpAdapterDomain = @"security.pEp.ObjCAdapter";
return nil;
break;
default:
if (![dict objectForKey:NSLocalizedDescriptionKey]) {
NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithDictionary:dict];
[dict2 setValue:localizedErrorStringFromPEPStatus(status)
forKey:NSLocalizedDescriptionKey];
dict = dict2;
}
default: {
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:localizedErrorStringFromPEPStatus(status),
NSLocalizedDescriptionKey, nil];
return [NSError errorWithDomain:s_pEpAdapterDomain code:status userInfo:dict];
}
break;
}
}
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
+ (NSError * _Nullable)errorWithPEPStatus:(PEPStatus)status
{
NSDictionary *userInfo = [NSDictionary new];
return [self errorWithPEPStatusInternal:status userInfo:userInfo];
return [self errorWithPEPStatusInternal:(PEP_STATUS) status];
}
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEP_STATUS)status
@ -85,15 +81,4 @@ NSString * _Nonnull stringFromPEPStatus(PEP_STATUS status) {
}
}
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
{
return [self errorWithPEPStatusInternal:(PEP_STATUS) status userInfo:dict];
}
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
{
return [self errorWithPEPStatusInternal:(PEP_STATUS) status userInfo:[NSDictionary new]];
}
@end

Loading…
Cancel
Save