forked from owncloud/ios-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNSError+MessageResolution.m
98 lines (77 loc) · 2.29 KB
/
NSError+MessageResolution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// NSError+MessageResolution.m
// ownCloud File Provider
//
// Created by Felix Schwarz on 09.04.19.
// Copyright © 2019 ownCloud GmbH. All rights reserved.
//
/*
* Copyright (C) 2019, ownCloud GmbH.
*
* This code is covered by the GNU Public License Version 3.
*
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/
#import <ownCloudSDK/ownCloudSDK.h>
#import "NSError+MessageResolution.h"
@implementation NSError (MessageResolution)
- (NSError *)resolvedErrorWithTranslation:(BOOL)withTranslation
{
if ([self.domain isEqual:OCErrorDomain])
{
NSErrorDomain errorDomain = self.domain;
NSInteger errorCode = self.code;
NSString *localizedDescription = self.localizedDescription;
NSString *localizedFailureReason = self.localizedFailureReason;
NSMutableDictionary *resolvedDict = [NSMutableDictionary new];
if (localizedDescription != nil)
{
resolvedDict[NSLocalizedDescriptionKey] = localizedDescription;
}
if (localizedFailureReason != nil)
{
resolvedDict[NSLocalizedFailureReasonErrorKey] = localizedFailureReason;
}
if (withTranslation)
{
errorDomain = NSCocoaErrorDomain;
resolvedDict[NSUnderlyingErrorKey] = self;
switch ((OCError)self.code)
{
case OCErrorItemAlreadyExists:
errorCode = NSFileWriteFileExistsError;
break;
case OCErrorItemNotFound:
case OCErrorItemDestinationNotFound:
case OCErrorFileNotFound:
errorCode = NSFileNoSuchFileError;
break;
case OCErrorFeatureNotImplemented:
case OCErrorItemOperationForbidden:
errorCode = NSFeatureUnsupportedError;
break;
case OCErrorItemInsufficientPermissions:
errorCode = NSFileWriteNoPermissionError;
break;
case OCErrorCancelled:
errorCode = NSUserCancelledError;
break;
case OCErrorInsufficientStorage:
errorCode = NSFileWriteOutOfSpaceError;
break;
default:
errorCode = NSFileReadUnknownError;
break;
}
}
return ([NSError errorWithDomain:errorDomain code:errorCode userInfo:resolvedDict]);
}
return (self);
}
- (NSError *)translatedError
{
return ([self resolvedErrorWithTranslation:YES]);
}
@end