Displaying custom error message with the right HTTP response codes

I’m building an RESTful API with CakePHP now. That is great stuff. Very easy and quick for the basics. Some more info on how to in the book and here.
But I wanted a custom XML error message with the right HTTP respond code like the Twitter API does. I knew it could be done with [...]