Commit fdb2606c by Dima Bart

Refactor generic request for URL to assert instead of return nil.

parent 2c0b946f
...@@ -556,14 +556,12 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token ...@@ -556,14 +556,12 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
- (NSURLSessionDataTask *)requestForURL:(NSURL *)url method:(NSString *)method object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler - (NSURLSessionDataTask *)requestForURL:(NSURL *)url method:(NSString *)method object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{ {
NSDictionary *json = [object jsonDictionaryForCheckout]; NSAssert(object, @"Failed to perform request. id<BUYSerializable> must not be nil.");
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:json options:0 error:&error]; NSData *data = [NSJSONSerialization dataWithJSONObject:[object jsonDictionaryForCheckout] options:0 error:nil];
NSURLSessionDataTask *task = nil; NSAssert(data, @"Failed to perform request. Could not serialize object. Possibly invalid object.");
if (data && !error) {
task = [self requestForURL:url method:method body:data completionHandler:completionHandler]; return [self requestForURL:url method:method body:data completionHandler:completionHandler];
}
return task;
} }
- (void)startTask:(NSURLSessionDataTask *)task - (void)startTask:(NSURLSessionDataTask *)task
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment