pEpObjCAdapter/NSError+PEP.m
changeset 512 6141a2d15f4f
parent 511 3b8b2a193fe9
child 513 f729b071c451
     1.1 --- a/pEpObjCAdapter/NSError+PEP.m	Wed Mar 07 15:18:30 2018 +0100
     1.2 +++ b/pEpObjCAdapter/NSError+PEP.m	Thu Mar 08 09:31:06 2018 +0100
     1.3 @@ -8,14 +8,20 @@
     1.4  
     1.5  #import "NSError+PEP.h"
     1.6  
     1.7 -static NSString *s_pEpAdapterDomain = @"pEpAdapter";
     1.8 +static NSString *s_pEpAdapterDomain = @"security.pEp.ObjCAdapter";
     1.9  
    1.10  @implementation NSError (Extension)
    1.11  
    1.12  + (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status
    1.13 -                                userInfo:(NSDictionary<NSErrorUserInfoKey, id> *)dict
    1.14 +                                userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
    1.15  {
    1.16      if (status != PEP_STATUS_OK && status != PEP_DECRYPTED && status != PEP_UNENCRYPTED) {
    1.17 +        if (![dict objectForKey:NSLocalizedDescriptionKey]) {
    1.18 +            NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithDictionary:dict];
    1.19 +            [dict2 setValue:localizedErrorStringFromPEPStatus(status)
    1.20 +                     forKey:NSLocalizedDescriptionKey];
    1.21 +            dict = dict2;
    1.22 +        }
    1.23          return [NSError errorWithDomain:s_pEpAdapterDomain code:status userInfo:dict];
    1.24      }
    1.25      return nil;
    1.26 @@ -23,7 +29,8 @@
    1.27  
    1.28  + (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status
    1.29  {
    1.30 -    return [self errorWithPEPStatus:status userInfo:nil];
    1.31 +    NSDictionary *userInfo = [NSDictionary new];
    1.32 +    return [self errorWithPEPStatus:status userInfo:userInfo];
    1.33  }
    1.34  
    1.35  + (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEP_STATUS)status
    1.36 @@ -42,6 +49,13 @@
    1.37      }
    1.38  }
    1.39  
    1.40 +/**
    1.41 + Could in theory return a fully localized version of the underlying error.
    1.42 + */
    1.43 +NSString * _Nonnull localizedErrorStringFromPEPStatus(PEP_STATUS status) {
    1.44 +    return stringFromPEPStatus(status);
    1.45 +}
    1.46 +
    1.47  NSString * _Nonnull stringFromPEPStatus(PEP_STATUS status) {
    1.48      switch (status) {
    1.49          case PEP_STATUS_OK: return @"PEP_STATUS_OK";