|
7 | 7 | from safety.formatter import report, license_report
|
8 | 8 | import itertools
|
9 | 9 | from safety.util import read_requirements, read_vulnerabilities, get_proxy_dict, get_packages_licenses
|
10 |
| -from safety.errors import DatabaseFetchError, DatabaseFileNotFoundError, InvalidKeyError |
| 10 | +from safety.errors import DatabaseFetchError, DatabaseFileNotFoundError, InvalidKeyError, TooManyRequestsError |
11 | 11 |
|
12 | 12 | try:
|
13 | 13 | from json.decoder import JSONDecodeError
|
@@ -151,7 +151,26 @@ def license(key, db, cache, files, proxyprotocol, proxyhost, proxyport):
|
151 | 151 | ]
|
152 | 152 |
|
153 | 153 | proxy_dictionary = get_proxy_dict(proxyprotocol, proxyhost, proxyport)
|
154 |
| - licenses_db = safety.get_licenses(key, db, cache, proxy_dictionary) |
| 154 | + try: |
| 155 | + licenses_db = safety.get_licenses(key, db, cache, proxy_dictionary) |
| 156 | + except InvalidKeyError: |
| 157 | + click.secho("Your API Key '{key}' is invalid. See {link}".format( |
| 158 | + key=key, link='https://goo.gl/O7Y1rS'), |
| 159 | + fg="red", |
| 160 | + file=sys.stderr) |
| 161 | + sys.exit(-1) |
| 162 | + except DatabaseFileNotFoundError: |
| 163 | + click.secho("Unable to load licenses database from {db}".format(db=db), fg="red", file=sys.stderr) |
| 164 | + sys.exit(-1) |
| 165 | + except TooManyRequestsError: |
| 166 | + click.secho("Unable to load licenses database (Too many requests, please wait before another request)", |
| 167 | + fg="red", |
| 168 | + file=sys.stderr |
| 169 | + ) |
| 170 | + sys.exit(-1) |
| 171 | + except DatabaseFetchError: |
| 172 | + click.secho("Unable to load licenses database", fg="red", file=sys.stderr) |
| 173 | + sys.exit(-1) |
155 | 174 | filtered_packages_licenses = get_packages_licenses(packages, licenses_db)
|
156 | 175 | output_report = license_report(packages=packages, licenses=filtered_packages_licenses)
|
157 | 176 | click.secho(output_report, nl=True)
|
|
0 commit comments