From 39477aa15629340523b8a092dce52eea18716518 Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Mon, 8 Aug 2022 11:17:56 +0100 Subject: [PATCH] BugsnagApiClientDeliveryStatus -> BSGDeliveryStatus --- Bugsnag/Delivery/BSGEventUploadOperation.m | 8 ++--- Bugsnag/Delivery/BSGSessionUploader.m | 28 +++++++++--------- Bugsnag/Delivery/BugsnagApiClient.h | 10 +++---- Bugsnag/Delivery/BugsnagApiClient.m | 10 +++---- Tests/BugsnagTests/BugsnagApiClientTest.m | 34 +++++++++++----------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Bugsnag/Delivery/BSGEventUploadOperation.m b/Bugsnag/Delivery/BSGEventUploadOperation.m index 8d3fa0e35..7ff7bee91 100644 --- a/Bugsnag/Delivery/BSGEventUploadOperation.m +++ b/Bugsnag/Delivery/BSGEventUploadOperation.m @@ -140,19 +140,19 @@ - (void)runWithDelegate:(id)delegate completion return; } - BSGPostJSONData(configuration.session, data, requestHeaders, notifyURL, ^(BugsnagApiClientDeliveryStatus status, __unused NSError *deliveryError) { + BSGPostJSONData(configuration.session, data, requestHeaders, notifyURL, ^(BSGDeliveryStatus status, __unused NSError *deliveryError) { switch (status) { - case BugsnagApiClientDeliveryStatusDelivered: + case BSGDeliveryStatusDelivered: bsg_log_debug(@"Uploaded event %@", self.name); [self deleteEvent]; break; - case BugsnagApiClientDeliveryStatusFailed: + case BSGDeliveryStatusFailed: bsg_log_debug(@"Upload failed retryably for event %@", self.name); [self prepareForRetry:originalPayload ?: eventPayload HTTPBodySize:data.length]; break; - case BugsnagApiClientDeliveryStatusUndeliverable: + case BSGDeliveryStatusUndeliverable: bsg_log_debug(@"Upload failed; will discard event %@", self.name); [self deleteEvent]; break; diff --git a/Bugsnag/Delivery/BSGSessionUploader.m b/Bugsnag/Delivery/BSGSessionUploader.m index 6cb3dd130..6af243593 100644 --- a/Bugsnag/Delivery/BSGSessionUploader.m +++ b/Bugsnag/Delivery/BSGSessionUploader.m @@ -46,17 +46,17 @@ - (instancetype)initWithConfig:(BugsnagConfiguration *)config notifier:(BugsnagN } - (void)uploadSession:(BugsnagSession *)session { - [self sendSession:session completionHandler:^(BugsnagApiClientDeliveryStatus status) { + [self sendSession:session completionHandler:^(BSGDeliveryStatus status) { switch (status) { - case BugsnagApiClientDeliveryStatusDelivered: + case BSGDeliveryStatusDelivered: [self processStoredSessions]; break; - case BugsnagApiClientDeliveryStatusFailed: + case BSGDeliveryStatusFailed: [self storeSession:session]; // Retry later break; - case BugsnagApiClientDeliveryStatusUndeliverable: + case BSGDeliveryStatusUndeliverable: break; } }]; @@ -106,8 +106,8 @@ - (void)processStoredSessions { [self.activeIds addObject:file]; } - [self sendSession:session completionHandler:^(BugsnagApiClientDeliveryStatus status) { - if (status != BugsnagApiClientDeliveryStatusFailed) { + [self sendSession:session completionHandler:^(BSGDeliveryStatus status) { + if (status != BSGDeliveryStatusFailed) { [fileManager removeItemAtPath:file error:nil]; } @synchronized (self.activeIds) { @@ -133,18 +133,18 @@ - (void)pruneFiles { // // https://bugsnagsessiontrackingapi.docs.apiary.io/#reference/0/session/report-a-session-starting // -- (void)sendSession:(BugsnagSession *)session completionHandler:(nonnull void (^)(BugsnagApiClientDeliveryStatus status))completionHandler { +- (void)sendSession:(BugsnagSession *)session completionHandler:(nonnull void (^)(BSGDeliveryStatus status))completionHandler { NSString *apiKey = [self.config.apiKey copy]; if (!apiKey) { bsg_log_err(@"Cannot send session because no apiKey is configured."); - completionHandler(BugsnagApiClientDeliveryStatusUndeliverable); + completionHandler(BSGDeliveryStatusUndeliverable); return; } NSURL *url = self.config.sessionURL; if (!url) { bsg_log_err(@"Cannot send session because no endpoint is configured."); - completionHandler(BugsnagApiClientDeliveryStatusUndeliverable); + completionHandler(BSGDeliveryStatusUndeliverable); return; } @@ -167,19 +167,19 @@ - (void)sendSession:(BugsnagSession *)session completionHandler:(nonnull void (^ NSData *data = BSGJSONDataFromDictionary(payload, NULL); if (!data) { bsg_log_err(@"Failed to encode session %@", session.id); - completionHandler(BugsnagApiClientDeliveryStatusUndeliverable); + completionHandler(BSGDeliveryStatusUndeliverable); return; } - BSGPostJSONData(self.config.session, data, headers, url, ^(BugsnagApiClientDeliveryStatus status, NSError *error) { + BSGPostJSONData(self.config.session, data, headers, url, ^(BSGDeliveryStatus status, NSError *error) { switch (status) { - case BugsnagApiClientDeliveryStatusDelivered: + case BSGDeliveryStatusDelivered: bsg_log_info(@"Sent session %@", session.id); break; - case BugsnagApiClientDeliveryStatusFailed: + case BSGDeliveryStatusFailed: bsg_log_warn(@"Failed to send sessions: %@", error); break; - case BugsnagApiClientDeliveryStatusUndeliverable: + case BSGDeliveryStatusUndeliverable: bsg_log_warn(@"Failed to send sessions: %@", error); break; } diff --git a/Bugsnag/Delivery/BugsnagApiClient.h b/Bugsnag/Delivery/BugsnagApiClient.h index 0213eb762..4083ee761 100644 --- a/Bugsnag/Delivery/BugsnagApiClient.h +++ b/Bugsnag/Delivery/BugsnagApiClient.h @@ -15,20 +15,20 @@ static BugsnagHTTPHeaderName const BugsnagHTTPHeaderNamePayloadVersion = @"B static BugsnagHTTPHeaderName const BugsnagHTTPHeaderNameSentAt = @"Bugsnag-Sent-At"; static BugsnagHTTPHeaderName const BugsnagHTTPHeaderNameStacktraceTypes = @"Bugsnag-Stacktrace-Types"; -typedef NS_ENUM(NSInteger, BugsnagApiClientDeliveryStatus) { +typedef NS_ENUM(NSInteger, BSGDeliveryStatus) { /// The payload was delivered successfully and can be deleted. - BugsnagApiClientDeliveryStatusDelivered, + BSGDeliveryStatusDelivered, /// The payload was not delivered but can be retried, e.g. when there was a loss of connectivity. - BugsnagApiClientDeliveryStatusFailed, + BSGDeliveryStatusFailed, /// The payload cannot be delivered and should be deleted without attempting to retry. - BugsnagApiClientDeliveryStatusUndeliverable, + BSGDeliveryStatusUndeliverable, }; void BSGPostJSONData(NSURLSession *URLSession, NSData *data, NSDictionary *headers, NSURL *url, - void (^ completionHandler)(BugsnagApiClientDeliveryStatus status, NSError *_Nullable error)); + void (^ completionHandler)(BSGDeliveryStatus status, NSError *_Nullable error)); NSString *_Nullable BSGIntegrityHeaderValue(NSData *_Nullable data); diff --git a/Bugsnag/Delivery/BugsnagApiClient.m b/Bugsnag/Delivery/BugsnagApiClient.m index 998ad84de..2c98c1657 100644 --- a/Bugsnag/Delivery/BugsnagApiClient.m +++ b/Bugsnag/Delivery/BugsnagApiClient.m @@ -35,7 +35,7 @@ void BSGPostJSONData(NSURLSession *URLSession, NSData *data, NSDictionary *headers, NSURL *url, - void (^ completionHandler)(BugsnagApiClientDeliveryStatus status, NSError *_Nullable error)) { + void (^ completionHandler)(BSGDeliveryStatus status, NSError *_Nullable error)) { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15]; request.HTTPMethod = @"POST"; @@ -52,7 +52,7 @@ void BSGPostJSONData(NSURLSession *URLSession, [[URLSession uploadTaskWithRequest:request fromData:data completionHandler:^(__unused NSData *responseData, NSURLResponse *response, NSError *error) { if (![response isKindOfClass:[NSHTTPURLResponse class]]) { bsg_log_debug(@"Request to %@ completed with error %@", url, error); - completionHandler(BugsnagApiClientDeliveryStatusFailed, error ?: + completionHandler(BSGDeliveryStatusFailed, error ?: [NSError errorWithDomain:@"BugsnagApiClientErrorDomain" code:0 userInfo:@{ NSLocalizedDescriptionKey: @"Request failed: no response was received", NSURLErrorFailingURLErrorKey: url }]); @@ -63,7 +63,7 @@ void BSGPostJSONData(NSURLSession *URLSession, bsg_log_debug(@"Request to %@ completed with status code %ld", url, (long)statusCode); if (statusCode / 100 == 2) { - completionHandler(BugsnagApiClientDeliveryStatusDelivered, nil); + completionHandler(BSGDeliveryStatusDelivered, nil); return; } @@ -80,11 +80,11 @@ void BSGPostJSONData(NSURLSession *URLSession, statusCode != HTTPStatusCodeProxyAuthenticationRequired && statusCode != HTTPStatusCodeClientTimeout && statusCode != HTTPStatusCodeTooManyRequests) { - completionHandler(BugsnagApiClientDeliveryStatusUndeliverable, error); + completionHandler(BSGDeliveryStatusUndeliverable, error); return; } - completionHandler(BugsnagApiClientDeliveryStatusFailed, error); + completionHandler(BSGDeliveryStatusFailed, error); }] resume]; } diff --git a/Tests/BugsnagTests/BugsnagApiClientTest.m b/Tests/BugsnagTests/BugsnagApiClientTest.m index 9a4e910dd..4abfb2992 100644 --- a/Tests/BugsnagTests/BugsnagApiClientTest.m +++ b/Tests/BugsnagTests/BugsnagApiClientTest.m @@ -22,34 +22,34 @@ - (void)testHTTPStatusCodes { NSURL *url = [NSURL URLWithString:@"https://example.com"]; id URLSession = [[URLSessionMock alloc] init]; - void (^ test)(NSInteger, BugsnagApiClientDeliveryStatus, BOOL) = - ^(NSInteger statusCode, BugsnagApiClientDeliveryStatus expectedDeliveryStatus, BOOL expectError) { + void (^ test)(NSInteger, BSGDeliveryStatus, BOOL) = + ^(NSInteger statusCode, BSGDeliveryStatus expectedDeliveryStatus, BOOL expectError) { XCTestExpectation *expectation = [self expectationWithDescription:@"completionHandler should be called"]; id response = [[NSHTTPURLResponse alloc] initWithURL:url statusCode:statusCode HTTPVersion:@"1.1" headerFields:nil]; [URLSession mockData:[NSData data] response:response error:nil]; - BSGPostJSONData(URLSession, [NSData data], @{}, url, ^(BugsnagApiClientDeliveryStatus status, NSError * _Nullable error) { + BSGPostJSONData(URLSession, [NSData data], @{}, url, ^(BSGDeliveryStatus status, NSError * _Nullable error) { XCTAssertEqual(status, expectedDeliveryStatus); expectError ? XCTAssertNotNil(error) : XCTAssertNil(error); [expectation fulfill]; }); }; - test(200, BugsnagApiClientDeliveryStatusDelivered, NO); + test(200, BSGDeliveryStatusDelivered, NO); // Permanent failures - test(400, BugsnagApiClientDeliveryStatusUndeliverable, YES); - test(401, BugsnagApiClientDeliveryStatusUndeliverable, YES); - test(403, BugsnagApiClientDeliveryStatusUndeliverable, YES); - test(404, BugsnagApiClientDeliveryStatusUndeliverable, YES); - test(405, BugsnagApiClientDeliveryStatusUndeliverable, YES); - test(406, BugsnagApiClientDeliveryStatusUndeliverable, YES); + test(400, BSGDeliveryStatusUndeliverable, YES); + test(401, BSGDeliveryStatusUndeliverable, YES); + test(403, BSGDeliveryStatusUndeliverable, YES); + test(404, BSGDeliveryStatusUndeliverable, YES); + test(405, BSGDeliveryStatusUndeliverable, YES); + test(406, BSGDeliveryStatusUndeliverable, YES); // Transient failures - test(402, BugsnagApiClientDeliveryStatusFailed, YES); - test(407, BugsnagApiClientDeliveryStatusFailed, YES); - test(408, BugsnagApiClientDeliveryStatusFailed, YES); - test(429, BugsnagApiClientDeliveryStatusFailed, YES); - test(500, BugsnagApiClientDeliveryStatusFailed, YES); + test(402, BSGDeliveryStatusFailed, YES); + test(407, BSGDeliveryStatusFailed, YES); + test(408, BSGDeliveryStatusFailed, YES); + test(429, BSGDeliveryStatusFailed, YES); + test(500, BSGDeliveryStatusFailed, YES); [self waitForExpectationsWithTimeout:1 handler:nil]; } @@ -62,8 +62,8 @@ - (void)testNotConnectedToInternetError { [URLSession mockData:nil response:nil error:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNotConnectedToInternet userInfo:@{ NSURLErrorFailingURLErrorKey: url, }]]; - BSGPostJSONData(URLSession, [NSData data], @{}, url, ^(BugsnagApiClientDeliveryStatus status, NSError * _Nullable error) { - XCTAssertEqual(status, BugsnagApiClientDeliveryStatusFailed); + BSGPostJSONData(URLSession, [NSData data], @{}, url, ^(BSGDeliveryStatus status, NSError * _Nullable error) { + XCTAssertEqual(status, BSGDeliveryStatusFailed); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, NSURLErrorDomain); [expectation fulfill];