IOS-1480 NSError 2face.

IOS-1480
Dirk Zimmermann 4 years ago
parent b134bc3bd8
commit e33e22c5f4

@ -154,6 +154,7 @@
435796E21FB5E51A00395A9E /* PEPMessage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPMessage.m; sourceTree = "<group>"; };
435F5163222045FB006EB11F /* PEPIdentity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PEPIdentity.h; path = pEpObjCAdapterFramework/PEPIdentity.h; sourceTree = SOURCE_ROOT; };
435F518F22204A67006EB11F /* PEPSessionProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PEPSessionProtocol.h; path = pEpObjCAdapterFramework/PEPSessionProtocol.h; sourceTree = SOURCE_ROOT; };
4360A9FD2227CFA300E62E5A /* NSError+PEP+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSError+PEP+Internal.h"; sourceTree = "<group>"; };
43676B631C57EA1A00233933 /* 0xB623F674.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 0xB623F674.asc; sourceTree = "<group>"; };
43676B641C57EA1A00233933 /* B623F674_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = B623F674_sec.asc; sourceTree = "<group>"; };
438C4393216744DA00C7425B /* PEPSendMessageDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPSendMessageDelegate.h; sourceTree = "<group>"; };
@ -326,6 +327,7 @@
439D91A3208479EE003F6AC2 /* PEPAttachment.h */,
439D91A4208479EE003F6AC2 /* PEPAttachment.m */,
43DED784203C25E200D45CD6 /* NSError+PEP.h */,
4360A9FD2227CFA300E62E5A /* NSError+PEP+Internal.h */,
43DED785203C25E200D45CD6 /* NSError+PEP.m */,
434ED6D4207E27B8000A7590 /* PEPAutoPointer.h */,
434ED6D5207E27B8000A7590 /* PEPAutoPointer.m */,

@ -0,0 +1,41 @@
//
// NSError+PEP+Internal.h
// pEpObjCAdapter
//
// Created by Dirk Zimmermann on 28.02.19.
// Copyright © 2019 p≡p. All rights reserved.
//
#ifndef NSError_PEP_Internal_h
#define NSError_PEP_Internal_h
/**
Extension for creating `NSError`s from `PEP_STATUS`
*/
@interface NSError (Internal)
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict;
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status;
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict;
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status;
/**
If the given status indicates an error, tries to set the given error accordingly.
@return YES if the given status indicates an error condition, NO otherwise.
*/
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatusInternal:(PEP_STATUS)status;
/**
If the given status indicates an error, tries to set the given error accordingly.
@return YES if the given status indicates an error condition, NO otherwise.
*/
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEPStatus)status;
@end
#endif /* NSError_PEP_Internal_h */

@ -15,17 +15,6 @@
*/
@interface NSError (Extension)
+ (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict;
+ (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status;
/**
If the given status indicates an error, tries to set the given error accordingly.
@return YES if the given status indicates an error condition, NO otherwise.
*/
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEP_STATUS)status;
/**
A possible string representation of the error code if this is a pEp error.
@return A string representation of the pEp error code, if it's in the pEp domain.

@ -7,13 +7,16 @@
//
#import "NSError+PEP.h"
#import "NSError+PEP+Internal.h"
#import <PEPObjCAdapterFramework/PEPConstants.h>
static NSString *s_pEpAdapterDomain = @"security.pEp.ObjCAdapter";
@implementation NSError (Extension)
+ (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
{
switch (status) {
case PEP_STATUS_OK:
@ -36,15 +39,15 @@ static NSString *s_pEpAdapterDomain = @"security.pEp.ObjCAdapter";
}
}
+ (NSError * _Nonnull)errorWithPEPStatus:(PEP_STATUS)status
+ (NSError * _Nonnull)errorWithPEPStatusInternal:(PEP_STATUS)status
{
NSDictionary *userInfo = [NSDictionary new];
return [self errorWithPEPStatus:status userInfo:userInfo];
return [self errorWithPEPStatusInternal:status userInfo:userInfo];
}
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatus:(PEP_STATUS)status
{
NSError *theError = [self errorWithPEPStatus:status];
NSError *theError = [self errorWithPEPStatusInternal:status];
if (theError) {
if (error) {
*error = theError;
@ -156,4 +159,14 @@ NSString * _Nonnull stringFromPEPStatus(PEP_STATUS status) {
}
}
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
userInfo:(NSDictionary<NSErrorUserInfoKey, id> * _Nonnull)dict
{
[self errorWithPEPStatusInternal:(PEP_STATUS) status userInfo:dict];
}
+ (NSError * _Nonnull)errorWithPEPStatus:(PEPStatus)status
{
}
@end

@ -18,7 +18,7 @@
#import "NSDictionary+Debug.h"
#import <PEPObjCAdapterFramework/PEPIdentity.h>
#import "PEPMessage.h"
#import "NSError+PEP.h"
#import "NSError+PEP+Internal.h"
#import "PEPAutoPointer.h"
#import "NSNumber+PEPRating.h"
#import "NSMutableDictionary+PEP.h"

@ -15,7 +15,7 @@
#import "PEPQueue.h"
#import "PEPLock.h"
#import "PEPObjCAdapter.h"
#import "NSError+PEP.h"
#import "NSError+PEP+Internal.h"
#import "PEPSessionProvider.h"
#import "PEPInternalSession.h"
@ -131,7 +131,7 @@ static __weak PEPSync *s_pEpSync;
if (status != PEP_STATUS_OK) {
if (error) {
*error = [NSError errorWithPEPStatus:status];
*error = [NSError errorWithPEPStatusInternal:status];
}
return nil;
}

Loading…
Cancel
Save