pEpObjCAdapter/NSError+PEP.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 07 Mar 2018 13:56:59 +0100
changeset 509 101e7d1ad385
parent 508 1ed7124c1f11
child 510 4e572aad7f36
permissions -rw-r--r--
IOSAD-72 NSError+PEP treat PEP_DECRYPTED as non-error
dirk@483
     1
//
dirk@483
     2
//  NSError+PEP.m
dirk@483
     3
//  pEpObjCAdapter
dirk@483
     4
//
dirk@483
     5
//  Created by Dirk Zimmermann on 20.02.18.
dirk@483
     6
//  Copyright © 2018 p≡p. All rights reserved.
dirk@483
     7
//
dirk@483
     8
dirk@483
     9
#import "NSError+PEP.h"
dirk@483
    10
dirk@483
    11
@implementation NSError (Extension)
dirk@483
    12
dirk@483
    13
+ (NSError *)errorWithPEPStatus:(PEP_STATUS)status
dirk@483
    14
                       userInfo:(NSDictionary<NSErrorUserInfoKey, id> *)dict
dirk@483
    15
{
dirk@509
    16
    if (status != PEP_STATUS_OK && status != PEP_DECRYPTED) {
dirk@483
    17
        return [NSError errorWithDomain:@"pEp" code:status userInfo:dict];
dirk@483
    18
    }
dirk@483
    19
    return nil;
dirk@483
    20
}
dirk@483
    21
dirk@483
    22
+ (NSError *)errorWithPEPStatus:(PEP_STATUS)status
dirk@483
    23
{
dirk@483
    24
    return [self errorWithPEPStatus:status userInfo:nil];
dirk@483
    25
}
dirk@483
    26
dirk@508
    27
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEP_STATUS)status
dirk@507
    28
{
dirk@507
    29
    NSError *theError = [self errorWithPEPStatus:status];
dirk@507
    30
    if (theError) {
dirk@507
    31
        if (error) {
dirk@507
    32
            *error = theError;
dirk@507
    33
        }
dirk@507
    34
        return YES;
dirk@507
    35
    } else {
dirk@507
    36
        if (error) {
dirk@507
    37
            *error = nil;
dirk@507
    38
        }
dirk@507
    39
        return NO;
dirk@507
    40
    }
dirk@507
    41
}
dirk@507
    42
dirk@483
    43
@end