Esempio n. 1
0
 def _navitia_caller(self, query):
     try:
         return requests.get(query, headers={"Authorization": self.token}, timeout=self.timeout)
     except requests.exceptions.Timeout:
         logging.getLogger(__name__).error('call to navitia timeout')
         raise requests.exceptions.Timeout('call to navitia timeout, data : {}'.format(query))
     except requests.exceptions.RequestException:
         logging.getLogger(__name__).exception('call to navitia failed')
         # currently we reraise the previous exceptions
         raise exceptions.NavitiaError('call to navitia failed, data : {}'.format(query))
Esempio n. 2
0
    def navitia_caller(self, query):

        try:
            return requests.get(query,
                                auth=(self.token, None),
                                timeout=self.timeout)
        except (requests.exceptions.RequestException):
            logging.getLogger(__name__).exception('call to navitia failed')
            # currently we reraise the previous exceptions
            raise exceptions.NavitiaError(
                'call to navitia failed, data : {}'.format(query))
Esempio n. 3
0
        except exceptions.ObjectUnknown, e:
            response = self.get_post_error_response_and_log(e, 404)
            return response, 404

        except exceptions.InvalidJson, e:
            response = self.get_post_error_response_and_log(e, 404)
            return response, 400

        try:
            db.session.add(disruption)
            db.session.commit()
            db.session.refresh(disruption)

            if not chaos.utils.send_disruption_to_navitia(disruption):
                ex_msg = 'An error occurred during transferring this disruption to Navitia. Please try again'
                raise exceptions.NavitiaError(ex_msg)

            return marshal({'disruption': disruption},
                           one_disruption_fields), 201
        except exceptions.NavitiaError, e:
            db.session.delete(disruption)
            db.session.commit()
            return marshal({'error': {
                'message': '{}'.format(e.message)
            }}, error_fields), 503
        except Exception, e:
            db.session.rollback()
            return marshal({'error': {
                'message': '{}'.format(e.message)
            }}, error_fields), 500