Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZEUS-4329] Adde enum for Playback error reasons #17

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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