0

I'm fairly new to Python, mostly focused on building Azure Functions. I'm having trouble determining which exceptions to handle for the various Class/Method calls.

If I was using say, a Microsoft REST API, I could see which responses may be returned and handle accordingly.

The Azure Python SDK docs don't provide this same type of visibility into the failure patterns, at least not in context (the same doc). If I look at a single method, say BlobClient.from_blob_url() there is no indication in the doc of which Exceptions I might have to handle.

So how do I determine which errors to handle?

Do I make a call with bad parameters and see what that does? Do I make a call then somehow knock a service down and see what it does?

SeaDude
  • 3,725
  • 6
  • 31
  • 68
  • 1
    I don't think there's a good answer to this. You recognize the two possibilities: either the exceptions are documented, or you can only discover them as they are triggered. Haskell (and Java, to some extent) mitigate this problem by requiring that the errors that function could raise must be encoded in the signature of the function in order for the function to compile (Java by requiring a `throws` clause, Haskell by requiring a return type that can express the error). But in Python, short of digging through the source code yourself, you are left to stress-test your code as best you can. – chepner Aug 14 '21 at 02:12
  • Thanks. I think the failure modes [are documented](https://learn.microsoft.com/en-us/python/api/overview/azure/core-readme?view=azure-python#azureerror), they are just not connected to the calls that raise them. I have no idea which of these `BlobClient.from_blob_url` will raise without enumerating/probing the method myself. – SeaDude Aug 14 '21 at 02:19

1 Answers1

1

Errors from Azure functions comes from different origins like API endpoints, libraries, packages etc.

Below try and except is the basic ideal way to find the errors:

def func():
    try:
        # Some operations

    except AzureHttpError as error:
        if error.status_code == 200:
            return (message as error)
        else:
            logging.error(f'#### Status Code: {error.status_code} ####')
            return "return message"
    else:
        return (any info variable that needs to be returned.)

Also, we have few other exceptions from Azure SDK for Python such as below:

• azure.common.exceptions

• azure.common.AzureConflictHttpError

• azure.common.AzureException

• azure.common.AzureHttpError

• azure.common.AzureMissingResourceHttpError

Refer to the documentation for more insights

SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8