APIError
public enum APIError : LocalizedError
Represents various errors that can occur when interacting with the API.
The APIError
enum provides a comprehensive list of errors that can occur when interacting with the API.
Each case represents a specific type of error, and the associated values provide additional context or information
about the error.
See also
LocalizedError
for more information on localized error descriptions.
-
Indicates a response error with a specific status code and data.
This error occurs when the API returns a response with a non-success status code. The associated values provide the status code and the response data.
Declaration
Swift
case responseError(statusCode: Int, data: Data)
Parameters
statusCode
The HTTP status code of the response.
data
The response data.
-
Indicates an invalid response.
This error occurs when the API returns an invalid response, such as a response with missing or malformed data.
Declaration
Swift
case invalidResponse
-
Indicates a URL error.
This error occurs when there is an issue with the URL, such as a network connectivity problem or an invalid URL.
Declaration
Swift
case urlError(URLError)
Parameters
error
The underlying
URLError
that caused the failure. -
Indicates a decoding error.
This error occurs when there is an issue decoding the response data into the expected type.
Declaration
Swift
case decodingError(DecodingError)
Parameters
error
The underlying
DecodingError
that caused the failure. -
Indicates a failure to encode plain text with a specific encoding.
This error occurs when there is an issue encoding plain text data using the specified encoding.
Declaration
Swift
case failedToEncodePlainText(encoding: String.Encoding)
Parameters
encoding
The
String.Encoding
used for encoding. -
Indicates an unknown error.
This error occurs when an unknown error is encountered.
Declaration
Swift
case unknown(error: Error)
Parameters
error
The underlying
Error
that caused the failure. -
A localized message describing what error occurred.
This property provides a human-readable description of the error, which can be used for displaying error messages to the user.
Example usage:
let error: APIError = .invalidResponse print(error.errorDescription ?? "Unknown error") // Output: "Received invalid URL response"
Declaration
Swift
public var errorDescription: String? { get }
Return Value
A localized string describing the error.