When a publisher says they can't justify making the investment in publishing your book, of course it's crushing. You've put weeks, months, sometimes even years into producing the best work you can deliver, and it's reduced to a question of money: they don't think they will sell enough copies to make back their investment.
This is called rejecting the manuscript for financial reasons, and it happens more often than anyone wants to admit. It's often nothing personal and not a comment on your work product.
You need to think about how you'll respond to this. Even if your contract may not have any of the sections discussed in the previous post about accepting the manuscript there are rules about rejecting manuscripts for financial reasons that you should know.
1. Unless they have specifically said in the contract they can't do this, the publisher is always allowed to reject for financial reasons. That's not the issue. The issue is what happens next.
2. If the publisher rejects for financial reasons, they will only get their advances back if your contract specifically says they can. If the contract is silent and they ask for their money back, you shouldn't feel obligated to give it to them.
3. Unless you've signed a clause saying your work is a work for hire, you ordinarily have the right to take the book somewhere else and try to sell it. Some publishers may try to put a clause into your contract saying if you do this you have to reimburse your advances. You should push back hard on that kind of section: it's not standard and it's not fair.
Of course, this only really matters if your publisher isn't just running out of money. Yes, the legal criteria are all the same even if that's true. But why would you want to pick a fight with someone who can't afford to pay you if you win? There's no point having your manuscript locked up by a house that can't afford to pay the printers, and if they go bankrupt your book will be tied up in the bankruptcy for years. Best just to take the rejection and go elsewhere.
But no matter what happens, if your publisher is invoking financial reasons not to publish, and even if you're willing just to walk away, there's one last thing to consider. Even if your contract was work for hire, try asking for the rights back. Your editor might feel bad for you, or their legal department might tell them they should let you, and you might end up with a book you can sell to someone else.