except (MissingArgumentError, BadArgumentError), msg: raise BadRequest({ 'error': { 'message': str(msg) } }) except ResourceNotFound, msg: raise NotFound({ 'error': { 'message': str(msg) } }) except ResourceUnavailable, msg: raise Timeout({ 'error': { 'message': str(msg) } }) except Exception, msg: if self.context.sentry and self.context.sentry.dsn: client = raven.Client(dsn=self.context.sentry.dsn) identifier = client.get_ident(client.captureException()) self.context.logger.info( 'Error captured in Sentry. Reference: %s' % identifier ) raise def POST(self, *args, **kwargs): # this is necessary in case some other method (e.g PUT) overrides # this method. default_method = kwargs.pop('default_method', 'post')
try: result = method(**params) if isinstance(result, tuple): web.header('Content-Type', result[1]) return result[0] web.header('Content-Type', 'application/json') dumped = json.dumps(result) web.header('Content-Length', len(dumped)) return dumped except MissingOrBadArgumentError, msg: raise BadRequest(str(msg)) except ResourceNotFound, msg: raise web.webapi.NotFound(str(msg)) except ResourceUnavailable, msg: raise Timeout(str(msg)) def POST(self, *args, **kwargs): params = self._get_web_input_params() return self.GET(default_method='post', *args, **params) def PUT(self, *args, **kwargs): params = self._get_web_input_params() return self.GET(default_method='put', *args, **params) def _get_web_input_params(self, **extra): """Because of the stupidify of web.py we can't say that all just tell it to collect all POST or GET variables as arrays unless we explicitely list the defaults. So, try to look ahead at the class that will need the input and see
try: result = method(**params) if isinstance(result, tuple): web.header('Content-Type', result[1]) return result[0] web.header('Content-Type', 'application/json') dumped = json.dumps(result) web.header('Content-Length', len(dumped)) return dumped except (MissingArgumentError, BadArgumentError), msg: raise BadRequest(str(msg)) except ResourceNotFound, msg: raise web.webapi.NotFound(str(msg)) except ResourceUnavailable, msg: raise Timeout() # No message allowed in Timeout except Exception, msg: if self.context.sentry and self.context.sentry.dsn: client = raven.Client(dsn=self.context.sentry.dsn) identifier = client.get_ident(client.captureException()) self.context.logger.info( 'Error captured in Sentry. Reference: %s' % identifier) raise def POST(self, *args, **kwargs): params = self._get_web_input_params() return self.GET(default_method='post', *args, **params) def PUT(self, *args, **kwargs): params = self._get_web_input_params() return self.GET(default_method='put', *args, **params)