That's Mostly Harmless, and yes, Adams was quite depressed when he wrote it. I still don't hate that ending - I segued in my youth from these books straight into existential philosophy (I was a tiresome bore then and still am, apologies) and I could very much sympathise with Ford at the end finding it all hilarious. But you could easily stop reading at So Long and feel quite satisfied no matter your outlook, I think, even after shedding some tears for Marvin.
Ah yes, "thanks for the fish" was rather the book of unusual luck happening to poor Arthur.
But I also don't hate the ending of "Mostly harmless". It is a fitting end alltogether. Absurd and dark, just like the very beginning of the books are.