Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 error when publishing to channel that doesn't exist #75

Open
timc3 opened this issue Sep 27, 2010 · 0 comments
Open

500 error when publishing to channel that doesn't exist #75

timc3 opened this issue Sep 27, 2010 · 0 comments

Comments

@timc3
Copy link

timc3 commented Sep 27, 2010

Shouldn't this be handled by a 404 or just making it more graceful. Was also wondering whether the code should look like this:

class HookboxWebAPI(object):
    logger = logging.getLogger('HookboxRest')
def __init__(self, api):
    self.api = api

def __call__(self, environ, start_response):
    path = environ['PATH_INFO']
    handler = getattr(self, 'render_' + path[1:], None)
    if not handler:
        start_response('404 Not Found', ())
        return "Not Found"
    if not self.api.is_enabled():
        start_response('200 Ok', ())
        return json.dumps([False, { 'msg': "Rest api is disabled by configuration. (Please supply --rest-secret/-r option at start)" }])

    try:
        form = get_form(environ)
        secret = form.pop('security_token', None)
        self.api.authorize(secret)
        return handler(form, start_response)
    except ExpectedException, e:
        start_response('200 Ok', [])
        self.logger.warn('REST Error: %s' % e)
        return json.dumps([False, {'msg': str(e) }])
    except Exception, e:
        self.logger.warn('REST Error: %s', path, exc_info=True)
        start_response('500 Internal server error', [])
        return json.dumps([False, {'msg': str(e) }])

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant