def exception_handler(ex): from azure.core.exceptions import HttpResponseError, ODataV4Format if isinstance(ex, HttpResponseError): # Workaround for issue: https://github.com/Azure/azure-sdk-for-python/issues/1556 in track2 if hasattr(ex, 'model'): additional_properties = getattr(ex.model, 'additional_properties', {}) if 'Code' in additional_properties and 'Message' in additional_properties: ex.error = ODataV4Format({ 'code': additional_properties['Code'], 'message': additional_properties['Message'] }) raise HttpResponseError( message=additional_properties['Message'], error=ex.error, response=ex.response) elif hasattr(ex, 'error'): additional_properties = getattr(ex.error, 'additional_properties', {}) if 'Code' in additional_properties and 'Message' in additional_properties: ex.error.code = additional_properties['Code'] ex.error.message = additional_properties['Message'] ex.message = additional_properties['Message'] raise ex
def raise_error(self, body): error = body["error"] if body["error"].get("innerError", None): error = body["error"]["innerError"] http_response_error = HttpResponseError( message="({}): {}".format(error["code"], error["message"])) http_response_error.error = ODataV4Format(error) # set error.code raise http_response_error
async def _update_status(self): # type: () -> None if self._query_status is None: raise Exception("this poller has not been initialized") self._response = await self._query_status() # pylint: disable=E1102 if self._response is not None and self._response.error is not None: error = HttpResponseError( "Polling returned a status indicating an error state.", model=self._response) error.error = ODataV4Format(self._response.error.serialize()) raise error
def raise_error(response, errors, message): error_message = "({}) {}{}".format(errors[0]["code"], errors[0]["message"], message) error = HttpResponseError(message=error_message, response=response) error.error = ODataV4Format(errors[0]) raise error