refactor: improve alert error context and copy action

This commit is contained in:
世界
2026-02-08 18:25:55 +08:00
parent a86dfc26d1
commit 8897e6deeb
32 changed files with 125 additions and 82 deletions
@@ -7,24 +7,24 @@ open class BaseViewModel: ObservableObject {
public init() {}
public func showError(_ error: Error) {
alert = AlertState(error: error)
public func showError(_ error: Error, action: String) {
alert = AlertState(action: action, error: error)
}
public func execute(_ operation: () async throws -> Void) async {
public func execute(_ operation: () async throws -> Void, action: String) async {
do {
try await operation()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: action, error: error)
}
}
public func executeOnBackground(_ operation: @escaping @Sendable () async throws -> Void) async {
public func executeOnBackground(_ operation: @escaping @Sendable () async throws -> Void, action: String) async {
do {
try await operation()
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: action, error: error)
}
}
}