Repository navigation
Expand file tree
/
Copy pathCDAError.m
More file actions
57 lines (43 loc) · 1.36 KB
/
Copy pathCDAError.m
File metadata and controls
57 lines (43 loc) · 1.36 KB
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
//
// CDAError.m
// ContentfulSDK
//
// Created by Boris Bügling on 05/03/14.
//
//
#import "CDAError+Private.h"
#import "CDAResource+Private.h"
NSString* const CDAErrorDomain = @"CDAErrorDomain";
@interface CDAError ()
@property (nonatomic) NSDictionary* details;
@property (nonatomic) NSString* message;
@end
#pragma mark -
@implementation CDAError
+(NSError*)buildErrorWithCode:(NSInteger)code userInfo:(NSDictionary*)userInfo {
return [NSError errorWithDomain:CDAErrorDomain
code:code
userInfo:userInfo];
}
+(NSString *)CDAType {
return @"Error";
}
#pragma mark -
-(NSString *)description {
return [[self errorRepresentationWithCode:0] description];
}
-(NSError *)errorRepresentationWithCode:(NSInteger)code {
return [[self class] buildErrorWithCode:code
userInfo:@{ @"details": self.details ?: @{},
@"identifier": self.identifier,
NSLocalizedDescriptionKey: self.message ?: @"" }];
}
-(id)initWithDictionary:(NSDictionary *)dictionary client:(CDAClient*)client {
self = [super initWithDictionary:dictionary client:client];
if (self) {
self.details = dictionary[@"details"];
self.message = dictionary[@"message"];
}
return self;
}
@end