Skip to content

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

@timc3

Description

@timc3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions