move api custom exceptions to api.rb, improve debug logging of query_string