How to use the bravado.exception.HTTPError function in bravado

To help you get started, we’ve selected a few bravado 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 Yelp / bravado / bravado / exception.py View on Github external
exc_class = exception_families.get(
            (status_code // 100) * 100,
        ) or HTTPError

    return exc_class(response, message=message, swagger_result=swagger_result)


class HTTPRedirection(HTTPError):
    """3xx responses."""


class HTTPClientError(HTTPError):
    """4xx responses."""


class HTTPServerError(HTTPError):
    """5xx responses."""

    def __str__(self):
        # type: (...) -> str
        # Try to surface the most useful/relevant information available
        # since this is the first thing a developer sees when bad things
        # happen.
        status_and_reason = str(self.response)
        message = ': ' + self.message if self.message else ''
        text = ': ' + self.response.text if self.response.text else ''
        result = ': {0}'.format(self.swagger_result) \
            if self.swagger_result is not None else ''
        return '{0}{1}{2}{3}'.format(status_and_reason, message, text, result)


# The follow are based on the HTTP Status Code Registry at
github Yelp / paasta / paasta_tools / cli / cmds / status.py View on Github external
service: str,
    instance: str,
    output: List[str],
    system_paasta_config: SystemPaastaConfig,
    verbose: int,
) -> int:
    output.append("    instance: %s" % PaastaColors.blue(instance))
    client = get_paasta_api_client(cluster, system_paasta_config)
    if not client:
        paasta_print("Cannot get a paasta-api client")
        exit(1)
    try:
        status = client.service.status_instance(
            service=service, instance=instance, verbose=verbose
        ).result()
    except HTTPError as exc:
        output.append(PaastaColors.red(exc.response.text))
        return exc.status_code
    except (BravadoConnectionError, BravadoTimeoutError) as exc:
        output.append(
            PaastaColors.red(f"Could not connect to API: {exc.__class__.__name__}")
        )
        return 1
    except Exception:
        tb = sys.exc_info()[2]
        output.append(PaastaColors.red(f"Exception when talking to the API:"))
        output.extend(line.strip() for line in traceback.format_tb(tb))
        return 1

    if status.git_sha != "":
        output.append("    Git sha:    %s (desired)" % status.git_sha)
github Yelp / paasta / paasta_tools / cli / cmds / metastatus.py View on Github external
if not client:
        paasta_print("Cannot get a paasta-api client")
        exit(1)

    try:
        cmd_args, _ = get_paasta_metastatus_cmd_args(
            groupings=groupings,
            verbose=verbose,
            autoscaling_info=autoscaling_info,
            use_mesos_cache=use_mesos_cache,
        )
        res = client.metastatus.metastatus(
            cmd_args=[str(arg) for arg in cmd_args]
        ).result()
        output, exit_code = res.output, res.exit_code
    except HTTPError as exc:
        output, exit_code = exc.response.text, exc.status_code

    return exit_code, output
github Yelp / paasta / paasta_tools / cli / cmds / status.py View on Github external
service: str,
    instance: str,
    output: List[str],
    system_paasta_config: SystemPaastaConfig,
    verbose: int,
) -> int:
    output.append("    instance: %s" % PaastaColors.blue(instance))
    client = get_paasta_api_client(cluster, system_paasta_config)
    if not client:
        paasta_print("Cannot get a paasta-api client")
        exit(1)
    try:
        status = client.service.status_instance(
            service=service, instance=instance, verbose=verbose
        ).result()
    except HTTPError as exc:
        output.append(PaastaColors.red(exc.response.text))
        return exc.status_code
    except (BravadoConnectionError, BravadoTimeoutError) as exc:
        output.append(
            PaastaColors.red(f"Could not connect to API: {exc.__class__.__name__}")
        )
        return 1
    except Exception:
        tb = sys.exc_info()[2]
        output.append(PaastaColors.red(f"Exception when talking to the API:"))
        output.extend(line.strip() for line in traceback.format_tb(tb))
        return 1

    if status.git_sha != "":
        output.append("    Git sha:    %s (desired)" % status.git_sha)
github Yelp / paasta / paasta_tools / cli / cmds / start_stop_restart.py View on Github external
system_paasta_config = load_system_paasta_config()
        for cluster, services_instances in csi.items():
            client = get_paasta_api_client(cluster, system_paasta_config)
            if not client:
                paasta_print("Cannot get a paasta-api client")
                exit(1)

            for service, instances in services_instances.items():
                for instance in instances:
                    try:
                        client.service.instance_set_state(
                            service=service,
                            instance=instance,
                            desired_state=desired_state,
                        ).result()
                    except HTTPError as exc:
                        paasta_print(exc.response.text)
                        return exc.status_code

                return_val = 0

    if invalid_deploy_groups:
        paasta_print(f"No deploy tags found for {', '.join(invalid_deploy_groups)}.")
        paasta_print(f"Has {service} been deployed there yet?")
        return_val = 1

    return return_val
github Yelp / paasta / paasta_tools / cli / utils.py View on Github external
).result()
            return task
        tasks = api.service.tasks_instance(
            service=service,
            instance=instance,
            verbose=True,
            slave_hostname=slave_hostname,
        ).result()
    except HTTPNotFound:
        log.error(
            "Cannot find instance {}, for service {}, in cluster {}".format(
                instance, service, cluster
            )
        )
        raise PaastaTaskNotFound
    except HTTPError as e:
        log.error("Problem with API call to find task details")
        log.error(e.response.text)
        raise PaastaTaskNotFound
    if not tasks:
        log.error(
            "Cannot find any tasks on host: {} or with task_id: {}".format(
                slave_hostname, task_id
            )
        )
        raise PaastaTaskNotFound
    return tasks[0]
github neptune-ml / neptune-client / neptune / internal / threads / hardware_metric_reporting_thread.py View on Github external
def run(self):
        try:
            while not self.is_interrupted():
                before = time.time()

                try:
                    self.__metric_service.report_and_send(timestamp=time.time())
                except (NeptuneException, HTTPError) as e:
                    _logger.debug('Unexpected HTTP error in hardware metric reporting thread: %s', e)

                reporting_duration = time.time() - before

                time.sleep(max(0, self.__metric_sending_interval_seconds - reporting_duration))
        except Exception as e:
            _logger.debug('Unexpected error in hardware metric reporting thread: %s', e)
github Yelp / paasta / paasta_tools / cli / utils.py View on Github external
).result()
            return task
        tasks = api.service.tasks_instance(
            service=service,
            instance=instance,
            verbose=True,
            slave_hostname=slave_hostname,
        ).result()
    except HTTPNotFound:
        log.error("Cannot find instance {}, for service {}, in cluster {}".format(
            instance,
            service,
            cluster,
        ))
        raise PaastaTaskNotFound
    except HTTPError as e:
        log.error("Problem with API call to find task details")
        log.error(e.response.text)
        raise PaastaTaskNotFound
    if not tasks:
        log.error("Cannot find any tasks on host: {} or with task_id: {}".format(
            slave_hostname,
            task_id,
        ))
        raise PaastaTaskNotFound
    return tasks[0]
github Yelp / fuzz-lightyear / fuzz_lightyear / main.py View on Github external
if seed is not None:
        get_settings().seed = seed
    if disable_unicode:
        get_settings().unicode_enabled = False

    outputter = ResultFormatter()
    for result in generate_sequences(
        n=iterations,
        tests=tests,
    ):
        try:
            validate_sequence(result.requests, result.responses)
        except Exception as e:
            if (
                ignore_exceptions and
                isinstance(e, HTTPError)
            ):
                # This makes it look like a valid request sequence.
                result.responses.responses = result.requests
            else:
                outputter.record_exception(result, e)

        outputter.record_result(result)

    return outputter