Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Classes/JSONAPIErrorResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
@property (nonatomic, strong) NSString *detail;
@property (nonatomic, strong) NSArray *links;
@property (nonatomic, strong) NSArray *paths;
@property (nonatomic, strong) NSDictionary *source;

- (instancetype) initWithDictionary:(NSDictionary*)dictionary;

- (NSString *)sourcePointer;
- (NSString *)sourceParameter;

@end
27 changes: 27 additions & 0 deletions Classes/JSONAPIErrorResource.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,36 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary {
_detail = dictionary[@"detail"];
_links = dictionary[@"links"];
_paths = dictionary[@"paths"];
_source = dictionary[@"source"];
}

return self;
}

- (NSString *)sourcePointer
{
if (self.source) {
NSString *pointer = self.source[@"pointer"];

if (pointer) {
return pointer;
}
}

return nil;
}

- (NSString *)sourceParameter
{
if (self.source) {
NSString *parameter = self.source[@"parameter"];

if (parameter) {
return parameter;
}
}

return nil;
}

@end
23 changes: 13 additions & 10 deletions Project/JSONAPITests/error_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
},
"data": [],
"errors": [{
"id": "123456",
"href": "/internet/is/fun",
"status": "400",
"code": "123abc",
"title": "some title",
"detail": "some detail",
"links": ["a_link"],
"source": ["a_path"]
}]
}
"id": "123456",
"href": "/internet/is/fun",
"status": "400",
"code": "123abc",
"title": "some title",
"detail": "some detail",
"links": ["a_link"],
"source": {
"pointer": "/some/point",
"parameter": "a_parameter"
}
}]
}