How to use the falcon.HTTPInternalServerError 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 werwolfby / monitorrent / monitorrent / rest / topics.py View on Github external
def on_post(self, req, resp):
        body = req.json
        try:
            url = body['url']
            settings = body['settings']
            added = self.tracker_manager.add_topic(url, settings)
        except KeyError:
            raise falcon.HTTPBadRequest('WrongParameters', 'Can\'t add topic')
        if not added:
            raise falcon.HTTPInternalServerError('ServerError', 'Can\'t add topic')
        resp.status = falcon.HTTP_201
github openstack / monasca-api / monasca / v2 / reference / transforms.py View on Github external
def _list_transforms(self, tenant_id):
        try:
            transforms = self._transforms_repo.list_transforms(tenant_id)
            return json.dumps(transforms)
        except repository_exceptions.RepositoryException as ex:
            LOG.error(ex)
            raise falcon.HTTPInternalServerError('Service unavailable',
                                                 ex.message)
github IntelAI / inference-model-manager / management / management_api / utils / errors_handling.py View on Github external
def handler(ex, req, resp, params):
        message = "{} {} is not available".format(ex.name, ex.resource)
        logger.error(message)
        raise falcon.HTTPInternalServerError(message)
github vfrico / kge-server / rest-service / endpoints / datasets.py View on Github external
:param integer dataset_id: Unique ID of dataset
        :returns: The dataset with changed values
        :rtype: DatasetDTO
        """
        dataset_info = HTTPUserDatasetDTO()
        try:
            dataset_info.load(kwargs["dataset_info"])
        except KeyError:
            pass

        dataset_dao = data_access.DatasetDAO()
        if dataset_info.description is not None:
            res, err = dataset_dao.set_description(
                dataset_id, dataset_info.description)
            if res is None:
                raise falcon.HTTPInternalServerError(
                    title="Server Error",
                    description="Unable to process description param")

        resource, err = dataset_dao.get_dataset_by_id(dataset_id)
        response = {
            "dataset": resource.to_dict(),
        }
        resp.body = json.dumps(response)
        resp.content_type = 'application/json'
        resp.status = falcon.HTTP_200
github linkedin / iris-relay / src / iris_relay / app.py View on Github external
logger.error(e)
                logger.error('Callback ID not an integer: %s', payload['callback_id'])
                raise falcon.HTTPBadRequest('Bad Request', 'Callback id must be int')
            data = {'msg_id': msg_id,
                    'source': payload['user']['name'],
                    'content': payload['actions'][0]['name']}
            endpoint = self.config['iris']['hook']['slack']
            try:
                result = self.iclient.post(endpoint, data)
            except MaxRetryError as e:
                logger.error(e.reason)
                return
            if result.status == 400:
                raise falcon.HTTPBadRequest('Bad Request', '')
            elif result.status != 200:
                raise falcon.HTTPInternalServerError('Internal Server Error', 'Unknown response from the api')
            else:
                content = process_api_response(result.data)
                self.return_slack_message(resp, content)
            return
        except Exception:
            logger.exception('Unable to read payload from slack. Our post body: %s', req.context['body'])
            raise falcon.HTTPBadRequest('Bad Request', 'Unable to read the payload from slack')
github openstack / monasca-api / monasca_api / v2 / reference / alarming.py View on Github external
def send_event(self, message_queue, event_msg):
        try:
            message_queue.send_message(helpers.to_json(event_msg))
        except message_queue_exceptions.MessageQueueException as ex:
            LOG.exception(ex)
            raise falcon.HTTPInternalServerError(
                'Message queue service unavailable'.encode('utf8'),
                str(ex).encode('utf8'))
github openstack / monasca-api / monasca_api / v2 / reference / resource.py View on Github external
except exceptions.DoesNotExistException:
            raise falcon.HTTPNotFound

        except exceptions.MultipleMetricsException as ex:
            raise falcon.HTTPConflict("MultipleMetrics", str(ex))

        except exceptions.AlreadyExistsException as ex:
            raise falcon.HTTPConflict(ex.__class__.__name__, str(ex))

        except exceptions.InvalidUpdateException as ex:
            raise HTTPUnprocessableEntityError(ex.__class__.__name__, str(ex))

        except exceptions.RepositoryException as ex:
            LOG.exception(ex)
            msg = " ".join(map(str, ex.args[0].args))
            raise falcon.HTTPInternalServerError('The repository was unable '
                                                 'to process your request',
                                                 msg)

        except Exception as ex:
            LOG.exception(ex)
            raise falcon.HTTPInternalServerError('Service unavailable',
                                                 str(ex))
github maru-labo / doodle / examples / api_server_app / app.py View on Github external
if image is None:
            raise falcon.HTTPMissingParam('image')
        if not isinstance(image, list):
            raise falcon.HTTPInvalidParam('This params is must be "list" type.', 'image')
        try:
            request = create_request(1, image)
            future  = self.stub.Predict.future(request, 5.0)
            predict = future.result().outputs
            res.media = {key: tf.make_ndarray(predict[key]).tolist()
                         for key in self.predict_keys}
        except InvalidImageError as e:
            raise falcon.HTTPBadRequest('Invalid image data.')
        except Exception as e:
            self.logger.error(e)
            traceback.print_exc()
            raise falcon.HTTPInternalServerError()
github scality / RestBlockDriver / playground / server.py View on Github external
def destroy(self):
        """ Destroy facility for the Volume """
        try:
            os.remove(self._path)
        except OSError as ex:
            if ex.errno == errno.ENOENT:
                raise falcon.HTTPInternalServerError(
                    'Internal Server Error',
                    "File not found when expected to find it.")
            else:
                raise falcon.HTTPInternalServerError(
                    'Internal Server Error',
                    "Could not delete volume: %s" % (str(ex)))
github netgroup-polito / frog3 / Orchestrator / ServiceLayerApplication / service_layer_application.py View on Github external
json.loads(err.response.text))
            elif code == 403:
                raise falcon.HTTPForbidden(json.loads(err.response.text)['error']['title'],
                                              json.loads(err.response.text)) 
            elif code == 404: 
                raise falcon.HTTPNotFound()
            """
            raise
        except jsonschema.ValidationError as err:
            logging.exception(err.message)
            raise falcon.HTTPBadRequest('Bad Request',
                                        err.message)
 
        except ValueError:
            logging.exception("Malformed JSON")
            raise falcon.HTTPInternalServerError("Internal Server Error","Malformed JSON")
            """
            raise falcon.HTTPError(falcon.HTTP_753,
                                   'Malformed JSON',
                                   'Could not decode the request body. The '
                                   'JSON was incorrect.')
            """
        except falcon.HTTPError as err:
            logging.exception("Falcon "+err.title)
            raise
        
        except ingoingFlowruleMissing as err:
            logging.exception("Falcon "+err.get_mess())
            raise falcon.HTTPError(falcon.HTTP_753,
                                   'Ingoing flowrule missing',
                                   err.get_mess())
        except ManifestValidationError as err: