How to use the falcon.HTTP_500 function in falcon

To help you get started, we’ve selected a few falcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / dd-trace-py / tests / contrib / falcon / app / resources.py View on Github external
def on_get(self, req, resp, **kwargs):
        resp.status = falcon.HTTP_500
        resp.body = 'Failure'
github airshipit / drydock / python / drydock_provisioner / control / validation.py View on Github external
resp.status = falcon.HTTP_200
                resp.body = json.dumps(resp_message)
            else:
                resp_message = validation.to_dict()
                resp_message['code'] = 400
                resp.status = falcon.HTTP_400
                resp.body = json.dumps(resp_message)

        except errors.InvalidFormat as e:
            err_message = str(e)
            self.error(req.context, err_message)
            self.return_error(resp, falcon.HTTP_400, err_message)
        except Exception as ex:
            err_message = str(ex)
            self.error(req.context, err_message)
            self.return_error(resp, falcon.HTTP_500, err_message)
github metaspace2020 / metaspace / metaspace / mol-db / app / errors.py View on Github external
try:
    from collections import OrderedDict
except ImportError:
    OrderedDict = dict


OK = {'status': falcon.HTTP_200, 'code': 200}

ERR_UNKNOWN = {'status': falcon.HTTP_500, 'code': 500, 'title': 'Unknown Error'}

ERR_AUTH_REQUIRED = {'status': falcon.HTTP_401, 'code': 99, 'title': 'Authentication Required'}

ERR_BAD_REQUEST = {'status': falcon.HTTP_400, 'code': 88, 'title': 'Bad request'}

ERR_DATABASE_ROLLBACK = {'status': falcon.HTTP_500, 'code': 77, 'title': 'Database Rollback Error'}

ERR_NOT_SUPPORTED = {'status': falcon.HTTP_404, 'code': 10, 'title': 'Not Supported'}

ERR_OBJECT_NOT_EXISTS = {'status': falcon.HTTP_404, 'code': 21, 'title': 'Object Not Exists'}

ERR_PASSWORD_NOT_MATCH = {'status': falcon.HTTP_400, 'code': 22, 'title': 'Password Not Match'}


class AppError(Exception):
    def __init__(self, error=ERR_UNKNOWN, description=None):
        self.error = error
        self.error['description'] = description

    @property
    def code(self):
        return self.error['code']
github jgontrum / spacy-api-docker / displacy_service / server.py View on Github external
def on_get(self, req, resp):
        try:
            resp.body = json.dumps({
                "spacy": spacy.about.__version__
            }, sort_keys=True, indent=2)
            resp.content_type = 'text/string'
            resp.append_header('Access-Control-Allow-Origin', "*")
            resp.status = falcon.HTTP_200
        except Exception:
            resp.status = falcon.HTTP_500
github ziwon / falcon-rest-api / app / errors.py View on Github external
# -*- coding: utf-8 -*-

import json
import falcon

try:
    from collections import OrderedDict
except ImportError:
    OrderedDict = dict


OK = {"status": falcon.HTTP_200, "code": 200}

ERR_UNKNOWN = {"status": falcon.HTTP_500, "code": 500, "title": "Unknown Error"}

ERR_AUTH_REQUIRED = {
    "status": falcon.HTTP_401,
    "code": 99,
    "title": "Authentication Required",
}

ERR_INVALID_PARAMETER = {
    "status": falcon.HTTP_400,
    "code": 88,
    "title": "Invalid Parameter",
}

ERR_DATABASE_ROLLBACK = {
    "status": falcon.HTTP_500,
    "code": 77,
github airshipit / armada / armada / errors.py View on Github external
format_error_resp(
            req,
            resp,
            falcon.HTTP_500,
            error_type=ex.__class__.__name__,
            message="Unhandled Exception raised: %s" % str(ex),
            retry=True)


class AppError(Exception):
    """
    Base error containing enough information to make a shipyard formatted error
    """

    title = 'Internal Server Error'
    status = falcon.HTTP_500

    def __init__(
            self,
            title=None,
            description=None,
            error_list=None,
            info_list=None,
            status=None,
            retry=False,
    ):
        """
        :param description: The internal error description
        :param error_list: The list of errors
        :param status: The desired falcon HTTP response code
        :param title: The title of the error message
        :param error_list: A list of errors to be included in output
github att-comdev / shipyard / src / bin / shipyard_airflow / shipyard_airflow / errors.py View on Github external
def default_exception_handler(ex, req, resp, params):
    """
    Catch-all execption handler for standardized output.
    If this is a standard falcon HTTPError, rethrow it for handling
    """
    if isinstance(ex, falcon.HTTPError):
        # allow the falcon http errors to bubble up and get handled
        raise ex
    else:
        # take care of the uncaught stuff
        exc_string = traceback.format_exc()
        logging.error('Unhandled Exception being handled: \n%s', exc_string)
        format_error_resp(
            req,
            resp,
            falcon.HTTP_500,
            error_type=ex.__class__.__name__,
            message="Unhandled Exception raised: %s" % str(ex),
            retry=True
        )
github sikrvault / sikr / sikr / resources / auth / basicauth.py View on Github external
"""
        This method will check that the email and the token match, then logs
        in the user.
        """
        print(request.get_param('email'))
        try:
            user = User.get(username=request.get_param('login-email'))
            valid = user.check_password(request.body['login-password'])
            print("WHATEVER: " + request)
            if valid:
                pass
            response.status = falcon.HTTP_200
            response.body = 'Logged in'
        except:
            raise falcon.HTTPError(falcon.HTTP_500)
github ProjectMeniscus / meniscus / meniscus / validation / integration / falcon_hooks.py View on Github external
def _load_json_body(stream):
    try:
        raw_json = stream.read()
    except Exception as ex:
        raise falcon.HTTPError(falcon.HTTP_500, 'Streaming body I/O error')

    try:
        return json.loads(raw_json)
    except ValueError as ve:
        raise falcon.HTTPError(falcon.HTTP_400, 'Malformed JSON body')
github airshipit / armada / armada / api / controller / rollback.py View on Github external
def on_post(self, req, resp, release):
        try:
            with self.get_tiller(req, resp) as tiller:
                msg = self.handle(req, release, tiller)
                resp.body = json.dumps({
                    'message': msg,
                })
                resp.content_type = 'application/json'
                resp.status = falcon.HTTP_200
        except LockException as e:
            self.return_error(resp, falcon.HTTP_409, message=str(e))
        except Exception as e:
            self.logger.exception('Caught unexpected exception')
            err_message = 'Failed to rollback release: {}'.format(e)
            self.error(req.context, err_message)
            self.return_error(resp, falcon.HTTP_500, message=err_message)