File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,34 @@ - (void)test_request_synchronous
200200 [OHHTTPStubs removeAllStubs ];
201201}
202202
203+ - (void )test_response_code
204+ {
205+ [LeanplumHelper setup_method_swizzling ];
206+ [LeanplumHelper start_production_test ];
207+ [LPEventDataManager deleteEventsWithLimit: 10000 ];
208+ [LPNetworkEngine setupValidateOperation ];
209+ [Leanplum_Reachability online: YES ];
210+
211+ // Simulate error from http response code.
212+ [OHHTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest *request) {
213+ return [request.URL.host isEqualToString: API_HOST];;
214+ } withStubResponse: ^OHHTTPStubsResponse * _Nonnull (NSURLRequest * _Nonnull request) {
215+ NSData *data = [@" Fail" dataUsingEncoding: NSUTF8StringEncoding];
216+ return [OHHTTPStubsResponse responseWithData: data statusCode: 500 headers: nil ];
217+ }];
218+
219+ NSArray *events = [LPEventDataManager eventsWithLimit: 10000 ];
220+ XCTAssertTrue (events.count == 0 );
221+
222+ [[LeanplumRequest post: @" sample3" params: nil ] sendNow: YES ];
223+ [NSThread sleepForTimeInterval: 0.2 ];
224+ events = [LPEventDataManager eventsWithLimit: 10000 ];
225+ XCTAssertTrue (events.count == 1 );
226+
227+ [LPEventDataManager deleteEventsWithLimit: 10000 ];
228+ [OHHTTPStubs removeAllStubs ];
229+ }
230+
203231- (void )test_uuid
204232{
205233 [LeanplumHelper setup_method_swizzling ];
Original file line number Diff line number Diff line change @@ -165,10 +165,18 @@ - (void)runSynchronously:(BOOL)synchronous
165165 if (synchronous) {
166166 dispatch_semaphore_signal (sem);
167167 }
168+
169+ // Handle unsuccessful http response code.
170+ NSError *responseError = error;
171+ if (!responseError && [self HTTPStatusCode ] != 200 ) {
172+ responseError = [NSError errorWithDomain: NSURLErrorDomain
173+ code: [self HTTPStatusCode ]
174+ userInfo: nil ];
175+ }
168176
169- if (error ) {
177+ if (responseError ) {
170178 if (self.errorBlock ) {
171- self.errorBlock (self, error );
179+ self.errorBlock (self, responseError );
172180 }
173181 } else {
174182 if (self.responseBlock ) {
You can’t perform that action at this time.
0 commit comments