Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Modelerfour version: 4.15.416

**New Features**

- Add mapping of 401 to `ClientAuthenticationError` for default error map #763
- Updated minimum `azure-core` version to 1.8.0 #747
- Updated minimum `msrest` version to 0.6.18 #747
- Support for `multipart/form-data` #746
Expand Down
8 changes: 8 additions & 0 deletions autorest/codegen/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from itertools import chain
import logging
from typing import cast, Dict, List, Any, Optional, Union, Set, TypeVar

Expand Down Expand Up @@ -239,6 +240,13 @@ def default_exception(self) -> Optional[str]:
def status_code_exceptions(self) -> List[SchemaResponse]:
return [excp for excp in self.exceptions if list(excp.status_codes) != ["default"]]

@property
def status_code_exceptions_status_codes(self) -> List[Union[str, int]]:
"""Actually returns all of the status codes from exceptions (besides default)"""
return list(chain.from_iterable([
excp.status_codes for excp in self.status_code_exceptions
]))

def imports(self, code_model, async_mode: bool) -> FileImport:
file_import = FileImport()

Expand Down
1 change: 1 addition & 0 deletions autorest/codegen/models/operation_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(

def imports(self, async_mode: bool, has_schemas: bool) -> FileImport:
file_import = FileImport()
file_import.add_from_import("azure.core.exceptions", "ClientAuthenticationError", ImportType.AZURECORE)
file_import.add_from_import("azure.core.exceptions", "ResourceNotFoundError", ImportType.AZURECORE)
file_import.add_from_import("azure.core.exceptions", "ResourceExistsError", ImportType.AZURECORE)
for operation in self.operations:
Expand Down
15 changes: 11 additions & 4 deletions autorest/codegen/templates/operation_tools.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ else ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~
{% macro error_map(operation, code_model) %}
{%if operation.status_code_exceptions %}
error_map = {
{% if not [404] in operation.status_code_exceptions | map(attribute='status_codes') %}
{% if not 401 in operation.status_code_exceptions_status_codes %}
401: ClientAuthenticationError,
{% endif %}
{% if not 404 in operation.status_code_exceptions_status_codes %}
404: ResourceNotFoundError,
{% endif %}
{% if not [409] in operation.status_code_exceptions | map(attribute='status_codes') %}
{% if not 409 in operation.status_code_exceptions_status_codes %}
409: ResourceExistsError,
{% endif %}
{% for excep in operation.status_code_exceptions %}
{% for status_code in excep.status_codes %}
{% set error_model = ", model=self._deserialize(models." + excep.schema.serialization_type + ", response)" if excep.schema.is_exception else "" %}
{% set error_format = ", error_format=ARMErrorFormat" if code_model.options['azure_arm'] else "" %}
{% if status_code == 404 %}
{% if status_code == 401 %}
401: lambda response: ClientAuthenticationError(response=response{{ error_model }}{{ error_format }}),
{% elif status_code == 404 %}
404: lambda response: ResourceNotFoundError(response=response{{ error_model }}{{ error_format }}),
{% elif status_code == 409 %}
409: lambda response: ResourceExistsError(response=response{{ error_model }}{{ error_format }}),
Expand All @@ -61,7 +66,9 @@ error_map = {
{% endfor %}
}
{% else %}
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
{% endif %}
error_map.update(kwargs.pop('error_map', {})){%- endmacro -%}
{% macro response_handling(response) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async
Expand Down Expand Up @@ -54,7 +54,9 @@ async def get_null(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down Expand Up @@ -101,7 +103,9 @@ async def put_positive_duration(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"
Expand Down Expand Up @@ -147,7 +151,9 @@ async def get_positive_duration(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down Expand Up @@ -191,7 +197,9 @@ async def get_invalid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TYPE_CHECKING
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.tracing.decorator import distributed_trace
Expand Down Expand Up @@ -59,7 +59,9 @@ def get_null(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down Expand Up @@ -107,7 +109,9 @@ def put_positive_duration(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"
Expand Down Expand Up @@ -154,7 +158,9 @@ def get_positive_duration(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down Expand Up @@ -199,7 +205,9 @@ def get_invalid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async
Expand Down Expand Up @@ -56,7 +56,9 @@ async def post_required(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_custom_header = None
Expand Down Expand Up @@ -123,7 +125,9 @@ async def post_optional(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_custom_header = None
Expand Down Expand Up @@ -180,7 +184,9 @@ async def post_multi_param_groups(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_header_one = None
Expand Down Expand Up @@ -243,7 +249,9 @@ async def post_shared_parameter_group_object(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_header_one = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import TYPE_CHECKING
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.tracing.decorator import distributed_trace
Expand Down Expand Up @@ -61,7 +61,9 @@ def post_required(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_custom_header = None
Expand Down Expand Up @@ -129,7 +131,9 @@ def post_optional(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_custom_header = None
Expand Down Expand Up @@ -187,7 +191,9 @@ def post_multi_param_groups(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_header_one = None
Expand Down Expand Up @@ -251,7 +257,9 @@ def post_shared_parameter_group_object(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))

_header_one = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async
Expand Down Expand Up @@ -38,7 +38,9 @@ async def get_report(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Dict[str, int]]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import TYPE_CHECKING
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.tracing.decorator import distributed_trace
Expand Down Expand Up @@ -43,7 +43,9 @@ def get_report(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Dict[str, int]]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
accept = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
import warnings

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async
Expand Down Expand Up @@ -54,7 +54,9 @@ async def get_method_global_valid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2015-07-01-preview"
accept = "application/json"
Expand Down Expand Up @@ -97,7 +99,9 @@ async def get_method_global_not_provided_valid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2015-07-01-preview"
accept = "application/json"
Expand Down Expand Up @@ -140,7 +144,9 @@ async def get_path_global_valid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2015-07-01-preview"
accept = "application/json"
Expand Down Expand Up @@ -183,7 +189,9 @@ async def get_swagger_global_valid(
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {404: ResourceNotFoundError, 409: ResourceExistsError}
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2015-07-01-preview"
accept = "application/json"
Expand Down
Loading