I don't think Brexit is a good example because the EU never was a Sovereign, united state in the same way that, say, the US is. The UK already has its own independently functional institutions, separate from the EU, and an international recognition and identity outside of EU. Not the same as Catalan province.
I'm citing it just as a similar debate that was handled without the same drastic errors that Spain made, not that it parallels Catalan's debate in any other particular way. At least as of this writing, peaceful secessions involving voting for secession is still a rare enough thing that they are all unique snowflakes. (Ask me again in 10 years.) I'm sure the EU made errors; I mean, that's almost a vacuous statement because there are always errors. (Pro-Brexit made errors too; also equally a nearly vacuous statement.) But there were nowhere near this drastic.