Example #1
0
def report_error(
    error,
    request=None,
    extra_data=None,
    level='warning',
    prefix='Handled exception',
    skip_sentry=False,
    print_tb=False,
):
    """Wrapper for error reporting

    This can be used for store exceptions in error reporting solutions as
    rollbar while handling error gracefully and giving user cleaner message.
    """
    if HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'):
        rollbar.report_exc_info(request=request,
                                extra_data=extra_data,
                                level=level)

    if not skip_sentry and settings.SENTRY_DSN:
        sentry_sdk.capture_exception()

    LOGGER.error('%s: %s: %s', prefix, error.__class__.__name__,
                 force_text(error))
    if print_tb:
        LOGGER.exception(prefix)
Example #2
0
    def unit_post_save(self, unit, created):
        if created or unit.state != STATE_APPROVED:
            return

        stats = unit.translation.get_stats()
        is_approved = int(unit.translation.stats.approved_percent) == 100
        is_translated = int(stats.get('translated_percent', 0)) == 100
        is_fuzzy = int(stats.get('fuzzy_percent', 0)) == 100

        if is_approved and is_translated and not is_fuzzy:
            site_id, _ = os.path.splitext(
                os.path.split(unit.translation.filename)[-1]
            )
            try:
                r = requests.post(
                    self.PLATFORM_NOTIFY_URL,
                    json={'site_id': site_id},
                    # WANT: Optionally add extra headers to check
                    # coming from Weblate. (e.g. X-WEBLATE: <val>)
                )
                r.raise_for_status()
            except requests.exceptions.HTTPError:
                logger.exception(
                    'Call to UWAI Platform failed: %s', r.text
                )
        return