Skip to content

Commit

Permalink
Moved LiveApiClientError to LiveApiJsonTypes.swift, as well as added …
Browse files Browse the repository at this point in the history
…conformance to LocalizedError. Also LiveApiError is now LiveApiClient.LiveApiError
  • Loading branch information
sqeezelemon committed Jul 30, 2021
1 parent 84157f5 commit 0a4401f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
10 changes: 0 additions & 10 deletions Sources/SwiftyLiveApi/LiveApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,6 @@ public class LiveApiClient {

static let oceanicTracks = "/public/v2/tracks"
}

//MARK: Custom errors
public enum LiveApiClientError: String, Error {
case requestLimitReached = "Reached request limit"
case dataIsNil = "Data returned nil"
case tooManyUsers = "Request contained too much items (25 items max)"
case failedToEncodeRequestBody = "Failed to encode request body"
case emptyrequestParameters = "All of the request parameters were empty"
case invalidUrl = "Request URL is invalid"
}
}

///enum that contains ```sessionId```s of servers for your convenience. Automatically fills when ```getSessions``` is called without errors, but can also be filled manually using ```updateSessionIds(sessions: [Session])```.
Expand Down
66 changes: 51 additions & 15 deletions Sources/SwiftyLiveApi/LiveApiJsonTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,28 @@ public enum GradeState: Int {
case warning = 2
}

//MARK: Error Code types

public enum LiveApiError: Int, Error {
case ok = 0
case userNotFound = 1
case missingRequestParameters = 2
case endpointError = 3
case notAuthorized = 4
case serverNotFound = 5
case flightNotFound = 6
case noAtisAvailable = 7

// Error just in case
case unknownErrorCode = 404
//MARK: LiveAPI error

@available(*, deprecated, renamed: "LiveApiClient.LiveApiError")
typealias LiveApiError = LiveApiClient.LiveApiError

extension LiveApiClient {
public enum LiveApiError: Int, Error {
case ok = 0
case userNotFound = 1
case missingRequestParameters = 2
case endpointError = 3
case notAuthorized = 4
case serverNotFound = 5
case flightNotFound = 6
case noAtisAvailable = 7

// Error just in case
case unknownErrorCode = 404
}
}

extension LiveApiError: LocalizedError {
extension LiveApiClient.LiveApiError: LocalizedError {
public var errorDescription: String? {
switch self {
case .ok:
Expand All @@ -530,3 +535,34 @@ extension LiveApiError: LocalizedError {
}
}
}

//MARK: Client errors
extension LiveApiClient {
public enum LiveApiClientError: String, Error {
case requestLimitReached = "Reached request limit"
case dataIsNil = "Data returned nil"
case tooManyUsers = "Request contained too much items (25 items max)"
case failedToEncodeRequestBody = "Failed to encode request body"
case emptyrequestParameters = "All of the request parameters were empty"
case invalidUrl = "Request URL is invalid"
}
}

extension LiveApiClient.LiveApiClientError: LocalizedError {
public var errorDescription: String? {
switch self {
case .dataIsNil:
return "Data returned nil"
case .requestLimitReached:
return "Request limit reached"
case .tooManyUsers:
return "Too many users (max 25)"
case .failedToEncodeRequestBody:
return "Failed to encode request body"
case .emptyrequestParameters:
return "All request parameters are empty"
case .invalidUrl:
return "Request URL is invalid"
}
}
}

0 comments on commit 0a4401f

Please sign in to comment.