-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIRWebAPIInterface+Validators.m
More file actions
49 lines (28 loc) · 1.01 KB
/
IRWebAPIInterface+Validators.m
File metadata and controls
49 lines (28 loc) · 1.01 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
//
// IRWebAPIInterface+Validators.m
// IRWebAPIKit
//
// Created by Evadne Wu on 1/29/11.
// Copyright 2011 Iridia Productions. All rights reserved.
//
#import "IRWebAPIKit.h"
@implementation IRWebAPIInterface (Validators)
+ (IRWebAPIResposeValidator) defaultNoErrorValidator {
return [[(^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)[inResponseContext objectForKey:kIRWebAPIEngineResponseContextURLResponse];
BOOL noError = ([response statusCode] == 200);
if (!noError) {
IRWebAPIKitLog(@"Error: %x %@", [response statusCode], [[response class] localizedStringForStatusCode:[response statusCode]]);
if ([inResponseOrNil isEqual:[NSNull null]]) {
return NO;
}
id errorContent = nil;
if ((errorContent = [inResponseOrNil valueForKeyPath:@"error"])) {
IRWebAPIKitLog(@"Error from Server: %@", errorContent);
}
return NO;
}
return YES;
}) copy] autorelease];
}
@end