File: exception_handler.py

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (31 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger
from knack.util import CLIError

logger = get_logger(__name__)


def azure_devops_exception_handler(ex):
    # we are taking dependency on string here because taking dependency on
    # Azure DevOps Client will increase load time for every command
    exceptionTypeName = type(ex).__name__
    if exceptionTypeName == 'AzureDevOpsServiceError':
        logger.debug('handling vsts service error')
        raise CLIError(ex)

    if exceptionTypeName == 'AzureDevOpsAuthenticationError':
        logger.debug('handling vsts auth error')
        raise CLIError(ex)

    if exceptionTypeName == 'ValueError':
        logger.debug('handling value error')
        raise CLIError(ex)

    logger.debug('handling generic error')
    import sys
    from six import reraise
    reraise(*sys.exc_info())