ApiClient: Don't try to write to closed streams

refs #6892