I've made an extension for Publisher to simplify sink, but my backend (not made by me) is messed up and I have a custom error that shouldn't be an error, and I want to return .success.
extension Publisher {
func sinkToResult(_ result: @escaping ((Result<Self.Output, Self.Failure>) -> Void)) -> AnyCancellable {
return sink(receiveCompletion: { completion in
switch completion {
case .failure(let error):
if let error = error as? ApiError, let globalError = error.globalErrors.first, globalError.code == 2233 {
//Here i want to send something like return(.success(true))
}
result(.failure(error))
case .finished:
break
}
},
receiveValue: { output in
result(.success(output))
})
}
}
Can you help me to create a custom Output.Self type that I can return here?