1# --------------------------------------------------------------------------------------------
2# Copyright (c) Microsoft Corporation. All rights reserved.
3# Licensed under the MIT License. See License.txt in the project root for license information.
4# --------------------------------------------------------------------------------------------
5
6from knack.util import CLIError
7
8
9def bot_exception_handler(ex):
10    from azure.mgmt.botservice.models import ErrorException
11    from msrestazure.azure_exceptions import CloudError
12    from msrest.exceptions import ClientRequestError  # pylint: disable=import-error
13    if isinstance(ex, ErrorException):
14        message = 'An error occurred. {0}: {1}'.format(
15            ex.error.error.code,
16            ex.error.error.message
17        )
18        raise CLIError(message)
19    if isinstance(ex, CloudError) and ex.status_code == 404:
20        return None
21    if isinstance(ex, ClientRequestError):
22        message = 'Error occurred in sending request. Please file an issue on {0}'.format(
23            'https://github.com/microsoft/botframework-sdk'
24        )
25        raise CLIError(message)
26    message = 'Unknown error during execution. Please file an issue on {0}'.format(
27        'https://github.com/microsoft/botframework-sdk'
28    )
29    raise CLIError(message)
30