Skip to content

Commit 749fdf1

Browse files
authored
feat(error): add affected resources in error (#95)
feat(error): add affected resources in error Add affected channels and groups under `affected` resources list.
1 parent dbbbd10 commit 749fdf1

File tree

9 files changed

+50
-11
lines changed

9 files changed

+50
-11
lines changed

.pubnub.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
---
22
name: swift
33
scm: github.com/pubnub/swift
4-
version: "5.0.1"
4+
version: "5.1.0"
55
schema: 1
66
changelog:
7+
- date: 2022-02-02
8+
version: 5.1.0
9+
changes:
10+
- type: feature
11+
text: "Add affected channels and groups under `affected` resources list."
712
- date: 2022-01-19
813
version: 5.0.1
914
changes:
@@ -439,7 +444,7 @@ sdks:
439444
- distribution-type: source
440445
distribution-repository: GitHub release
441446
package-name: PubNub
442-
location: https://github.com/pubnub/swift/archive/refs/tags/5.0.1.zip
447+
location: https://github.com/pubnub/swift/archive/refs/tags/5.1.0.zip
443448
supported-platforms:
444449
supported-operating-systems:
445450
macOS:

Examples/Sources/MasterDetailTableViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ class MasterDetailTableViewController: UITableViewController {
308308
print("A file was uplaoded \(file)")
309309
case let .subscribeError(error):
310310
print("The following error was generated during subscription \(error.localizedDescription)")
311+
error.affected.forEach {
312+
switch $0 {
313+
case let .channels(affectedChannels):
314+
print("Affected channels: \(affectedChannels)")
315+
case let .channelGroups(affectedChannelGroups):
316+
print("Affected channel groups: \(affectedChannelGroups)")
317+
default:
318+
break
319+
}
320+
}
311321
print("If `disconnectedUnexpectedly` also occurred then subscription has stopped, and needs to be restarted")
312322
}
313323
}

PubNub.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@
25062506
"$(inherited)",
25072507
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
25082508
);
2509-
MARKETING_VERSION = 5.0.1;
2509+
MARKETING_VERSION = 5.1.0;
25102510
OTHER_CFLAGS = "$(inherited)";
25112511
OTHER_LDFLAGS = "$(inherited)";
25122512
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -2539,7 +2539,7 @@
25392539
"$(inherited)",
25402540
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
25412541
);
2542-
MARKETING_VERSION = 5.0.1;
2542+
MARKETING_VERSION = 5.1.0;
25432543
OTHER_CFLAGS = "$(inherited)";
25442544
OTHER_LDFLAGS = "$(inherited)";
25452545
OTHER_SWIFT_FLAGS = "$(inherited)";

PubNubSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PubNubSwift'
3-
s.version = '5.0.1'
3+
s.version = '5.1.0'
44
s.homepage = 'https://github.com/pubnub/swift'
55
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
66
s.authors = { 'PubNub, Inc.' => '[email protected]' }

Sources/PubNub/Errors/PubNubError.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public struct PubNubError: Error {
6666
case response(HTTPURLResponse)
6767
case json(AnyJSON)
6868
case subscribe(SubscribeCursor)
69+
case channels([String])
70+
case channelGroups([String])
6971
}
7072

7173
/// The PubNubError specific Domain that groups together the different Reasons
@@ -255,7 +257,9 @@ public struct PubNubError: Error {
255257
router: HTTPRouter?,
256258
request: URLRequest?,
257259
response: HTTPURLResponse?,
258-
additional details: [ErrorDetail]? = nil
260+
additional details: [ErrorDetail]? = nil,
261+
affectedChannels channels: [String]? = nil,
262+
affectedChannelGroups channelGroups: [String]? = nil
259263
) {
260264
var reasonOrResponse = reason
261265

@@ -268,6 +272,12 @@ public struct PubNubError: Error {
268272
reasonOrResponse = reasonOrResponse ?? Reason(rawValue: response.statusCode)
269273
affectedValues.append(.response(response))
270274
}
275+
if let channels = channels {
276+
affectedValues.append(.channels(channels))
277+
}
278+
if let channelGroups = channelGroups {
279+
affectedValues.append(.channelGroups(channelGroups))
280+
}
271281

272282
self.init(reasonOrResponse ?? .unrecognizedStatusCode,
273283
router: router,

Sources/PubNub/Helpers/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct Constant {
6262
}()
6363

6464
static let pubnubSwiftSDKVersion: String = {
65-
"5.0.1"
65+
"5.1.0"
6666
}()
6767

6868
static let appBundleId: String = {

Sources/PubNub/Networking/Response/GenericServicePayloadResponse.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,18 @@ struct GenericServicePayloadResponse: Codable, Hashable {
225225
let status: Int
226226
let error: Bool
227227
let channels: [String: [String]]
228+
let affectedChannels: [String]?
229+
let affectedChannelGroups: [String]?
228230

229231
init(
230232
message: EndpointResponseMessage? = nil,
231233
details: [ErrorDetail] = [],
232234
service: String? = nil,
233235
status: Int? = nil,
234236
error: Bool = false,
235-
channels: [String: [String]] = [:]
237+
channels: [String: [String]] = [:],
238+
affectedChannels: [String]? = nil,
239+
affectedChannelGroups: [String]? = nil
236240
) {
237241
if !error, HTTPURLResponse.successfulStatusCodes.contains(status ?? 0) {
238242
self.message = .acknowledge
@@ -245,6 +249,8 @@ struct GenericServicePayloadResponse: Codable, Hashable {
245249
self.status = status ?? -1
246250
self.error = error
247251
self.channels = channels
252+
self.affectedChannels = affectedChannels
253+
self.affectedChannelGroups = affectedChannelGroups
248254
}
249255

250256
enum CodingKeys: String, CodingKey {
@@ -254,6 +260,7 @@ struct GenericServicePayloadResponse: Codable, Hashable {
254260
case status
255261
case error
256262
case channels
263+
case payload
257264
}
258265

259266
init(from decoder: Decoder) throws {
@@ -289,13 +296,18 @@ struct GenericServicePayloadResponse: Codable, Hashable {
289296

290297
let status = try container.decodeIfPresent(Int.self, forKey: .status)
291298
let channels = try container.decodeIfPresent([String: [String]].self, forKey: .channels) ?? [:]
299+
let payload = try container.decodeIfPresent([String: [String]].self, forKey: .payload) ?? [:]
300+
let affectedChannels: [String]? = payload["channels"]
301+
let affectedChannelGroups: [String]? = payload["channel-groups"]
292302

293303
self.init(message: message ?? error,
294304
details: details,
295305
service: service,
296306
status: status,
297307
error: isError,
298-
channels: channels)
308+
channels: channels,
309+
affectedChannels: affectedChannels,
310+
affectedChannelGroups: affectedChannelGroups)
299311
}
300312

301313
func encode(to encoder: Encoder) throws {

Sources/PubNub/Networking/Response/ResponseOperator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ extension ResponseDecoder {
9595

9696
return PubNubError(reason: generalErrorPayload?.pubnubReason,
9797
router: router, request: request, response: response,
98-
additional: generalErrorPayload?.details)
98+
additional: generalErrorPayload?.details,
99+
affectedChannels: generalErrorPayload?.affectedChannels,
100+
affectedChannelGroups: generalErrorPayload?.affectedChannelGroups)
99101
}
100102
}
101103

Sources/PubNub/Subscription/SubscriptionSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SubscriptionSession {
3333

3434
public let uuid = UUID()
3535
let longPollingSession: SessionReplaceable
36-
internal(set) var configuration: SubscriptionConfiguration
36+
var configuration: SubscriptionConfiguration
3737
let sessionStream: SessionListener
3838

3939
/// PSV2 feature to subscribe with a custom filter expression.

0 commit comments

Comments
 (0)