~kf5jwc/garretts-plugin-google

ref: 69b80529b8014251aa2bbe6ce8182285f6f43aee garretts-plugin-google/text_synthesizer_plugin_google/exception_handler.py -rw-r--r-- 673 bytes View raw
69b80529 — Kyle Jones I should return the return from the original function. 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from google.auth.exceptions import DefaultCredentialsError
from text_synthesizer import PluginFileMissing

from .plugin_files import credentials_file


FILE_PROMPT = "Please select your credentials file."
INVALID_CREDS_MSG = """
Valid credentials for Google services were not found!\n\nYou can find out how to \
acquire this file from \
https://developers.google.com/accounts/docs/application-default-credentials.
"""


def exception_catcher(fn):
    def func(*args, **kwargs):
        try:
            return fn(*args, **kwargs)
        except DefaultCredentialsError:
            raise PluginFileMissing(credentials_file, INVALID_CREDS_MSG, FILE_PROMPT)

    return func