I think you should create your own exception class for this (one for 401 second for 400) and raise those. You can find some info here http://www.sinatrarb.com/intro.html#Not%20Found