Skip to content

Commit

Permalink
[ZEUS-4329] Adde enum for Playback error reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
KharchenkoAlex committed Jun 17, 2024
1 parent 5125186 commit b6dca19
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Sources/PlaybackSDK/PlayBack API/PlayBackAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ internal class PlayBackAPIService: PlayBackAPI {
return data
default:
let decoder = JSONDecoder()
if let errorResponse = try? decoder.decode(PlaybackResponseModel.self, from: data) {
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: errorResponse.message ?? "Unknown authentication error message", reason: errorResponse.reason ?? "Unknown authentication error reason")
if let errorResponse = try? decoder.decode(PlaybackResponseModel.self, from: data) {
let errorReason = errorResponse.reason ?? "Unknown authentication error reason"
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: errorResponse.message ?? "Unknown authentication error message", reason: PlaybackErrorReason(fromString: errorReason))
} else {
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: "Unknown authentication error", reason: "Unknown authentication error reason")
let errorReason = "Unknown authentication error reason"
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: "Unknown authentication error", reason: PlaybackErrorReason(fromString: errorReason))
}
}
}
Expand Down
49 changes: 48 additions & 1 deletion Sources/PlaybackSDK/PlayBackSDKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ public enum SDKError: Error {
case loadHLSStreamError
}

// Define reason codes returned by Playback SDK
public enum PlaybackErrorReason: Equatable {
// Http error 400
case headerError
case badRequestError
case siteNotFound
case configurationError
case apiKeyError
case mpPartnerError

// Http error 401
case tokenError
case tooManyDevices
case tooManyRequests
case noEntitlement
case noSubscription
case noActiveSession
case notAuthenticated

// Http error 404
case noEntityExist

// Unknown error with associated custom message
case unknownError(String)

init(fromString value: String) {
switch value.uppercased() {
case "HEADER_ERROR": self = .headerError
case "BAD_REQUEST_ERROR": self = .badRequestError
case "SITE_NOT_FOUND": self = .siteNotFound
case "CONFIGURATION_ERROR": self = .configurationError
case "API_KEY_ERROR": self = .apiKeyError
case "MP_PARTNER_ERROR": self = .mpPartnerError
case "TOKEN_ERROR": self = .tokenError
case "TOO_MANY_DEVICES": self = .tooManyDevices
case "TOO_MANY_REQUESTS": self = .tooManyRequests
case "NO_ENTITLEMENT": self = .noEntitlement
case "NO_SUBSCRIPTION": self = .noSubscription
case "NO_ACTIVE_SESSION": self = .noActiveSession
case "NOT_AUTHENTICATED": self = .notAuthenticated
case "NO_ENTITY_EXIST": self = .noEntityExist
default: self = .unknownError(value)
}
}
}


/**
Define the errors that can occur during API interactions
*/
Expand All @@ -30,7 +77,7 @@ public enum PlayBackAPIError: Error {
case loadHLSStreamError

case networkError(Error)
case apiError(statusCode: Int, message: String, reason: String)
case apiError(statusCode: Int, message: String, reason: PlaybackErrorReason)
}


Expand Down

0 comments on commit b6dca19

Please sign in to comment.