APIErrorType

public enum APIErrorType : Error

Enum for the possible API errors.

Subspec: Utility/APIError

func decodeData<T: Decodable>(_ data: Data?) -> Result<T> {
    guard let data = data else {
        return Result.failure(APIErrorType.noDataRetreived)
    }

    do {
        let model = try decoder.decode(T.self, from: data)
        return Result.success(model)
    } catch {
        return decodeError(data, decodeError: error)
    }
}

When decoding the objects from an API errors can be identified with the APIErrorType. In the example above the APIErrorType is used to identify when no data is returned from the API. The other options allows for identifying failed deserializations and custom error codes through the APIError model.

  • backend: Custom error message from backend.
  • noDataRetreived: Used when the data is nil from the api.
  • deserializationFailed: Used when the data can’t be deserialized into the desired model.
  • Undocumented

    Declaration

    Swift

    case backend(error: APIError)
  • Undocumented

    Declaration

    Swift

    case noDataRetreived
  • Undocumented

    Declaration

    Swift

    case deserializationFailed
  • Indicates if the error is recieved from the backend.

    Declaration

    Swift

    public var isBackendError: Bool { get }
  • Localized description.

    Declaration

    Swift

    public var localizedDescription: String { get }