def handle_cli_error(e, message: str = None, http_messages_mapping: Dict = None, sys_exit: bool = False): http_messages_mapping = http_messages_mapping or {} if message: Printer.print_error(message) if hasattr(e, "status"): if e.status not in [404, 401, 403]: Printer.print_error("Error message: {}.".format(e)) message = http_messages_mapping.get( e.status, HTTP_ERROR_MESSAGES_MAPPING.get(e.status)) Printer.print_error(message, sys_exit=sys_exit) elif hasattr(e, "message"): # Handling of HTML errors if "404" in e.message: message = http_messages_mapping.get( 404, HTTP_ERROR_MESSAGES_MAPPING.get(404)) Printer.print_error(message, sys_exit=sys_exit) elif "401" in e.message: message = http_messages_mapping.get( 401, HTTP_ERROR_MESSAGES_MAPPING.get(401)) Printer.print_error(message, sys_exit=sys_exit) elif "403" in e.message: message = http_messages_mapping.get( 403, HTTP_ERROR_MESSAGES_MAPPING.get(403)) Printer.print_error(message, sys_exit=sys_exit) else: Printer.print_error("Error message: {}.".format(e), sys_exit=sys_exit) else: Printer.print_error("Error message: {}.".format(e), sys_exit=sys_exit)
def handle_cli_error(e, message=None, sys_exit: bool = False): if message: Printer.print_error(message) if hasattr(e, "status"): Printer.print_error("Error message: {}.".format(e)) Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(e.status), sys_exit=sys_exit) else: Printer.print_error("Error message: {}.".format(e), sys_exit=sys_exit)
def handle_cli_error(e, message=None, sys_exit: bool = False): if message: Printer.print_error(message) if hasattr(e, "status"): if e.status not in [404, 401, 403]: Printer.print_error("Error message: {}.".format(e)) Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(e.status), sys_exit=sys_exit) elif hasattr(e, "message"): # Handling of HTML errors if "404" in e.message: Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(404), sys_exit=sys_exit) elif "401" in e.message: Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(401), sys_exit=sys_exit) elif "403" in e.message: Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(403), sys_exit=sys_exit) else: Printer.print_error("Error message: {}.".format(e), sys_exit=sys_exit) else: Printer.print_error("Error message: {}.".format(e), sys_exit=sys_exit)
def check_response_status(self, response, endpoint): """Check if response is successful. Else raise Exception.""" if 200 <= response.status_code < 300: return response try: logger.error( "Request to %s failed with status code %s. \n" "Reason: %s", endpoint, response.status_code, response.text, ) except TypeError: logger.error("Request to %s failed with status code", endpoint) raise PolyaxonClientException( HTTP_ERROR_MESSAGES_MAPPING.get(response.status_code))
def handle_cli_error(e, message=None): if message: Printer.print_error(message) Printer.print_error("Error message: {}.".format(e)) if hasattr(e, "status"): Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(e.status))