I am developing an application on Google App Engine using Python.
I have a handler that can return various outputs (html and json at the moment), I am testing obvious errors in the system based on invalid parameters sent to the request handler.
However, what I am doing seems dirty (see below):
class FeedHandler(webapp.RequestHandler): def get(self): app = self.request.get("id") name = self.request.get("name") output_type = self.request.get("output", default_value = "html") pretty = self.request.get("pretty", default_value = "") application = model.Application.GetByKey(app) if application is None: if output_type == "json": self.response.out.write(simplejson.dumps({ "errorCode" : "Application not found."})) self.set_status(404) return category = model.FeedCategory.GetByKey(application, name) if category is None: if output_type == "json": self.response.out.write(simplejson.dumps({ "errorCode" : "Category not found."})) self.set_status(404) return
I specifically handle cases for each type of output, as well as for "assert".
I am fond of suggestions, examples, and examples of how to clean it (I know that it will be a nightmare to try and save what I am doing).
I play with the idea of ββhaving and raising custom exceptions and having a decorator that will automatically work out how to display error messages - I think this is a good idea, but I would like to get some feedback and suggestions based on how people did it in the past.
source share