|
5 | 5 | import os |
6 | 6 | from typing import Tuple |
7 | 7 |
|
8 | | -from google.api_core import retry |
9 | 8 | import requests |
10 | 9 | import requests.exceptions |
11 | 10 |
|
@@ -61,8 +60,6 @@ def __init__(self, |
61 | 60 | 'Authorization': 'Bearer %s' % api_key |
62 | 61 | } |
63 | 62 |
|
64 | | - @retry.Retry(predicate=retry.if_exception_type( |
65 | | - labelbox.exceptions.InternalServerError)) |
66 | 63 | def execute(self, query, params=None, timeout=10.0): |
67 | 64 | """ Sends a request to the server for the execution of the |
68 | 65 | given query. Checks the response for errors and wraps errors |
@@ -124,15 +121,12 @@ def convert_value(value): |
124 | 121 | "Unknown error during Client.query(): " + str(e), e) |
125 | 122 |
|
126 | 123 | try: |
127 | | - r_json = response.json() |
| 124 | + response = response.json() |
128 | 125 | except: |
129 | | - error_502 = '502 Bad Gateway' |
130 | | - if error_502 in response.text: |
131 | | - raise labelbox.exceptions.InternalServerError(error_502) |
132 | 126 | raise labelbox.exceptions.LabelboxError( |
133 | 127 | "Failed to parse response as JSON: %s" % response.text) |
134 | 128 |
|
135 | | - errors = r_json.get("errors", []) |
| 129 | + errors = response.get("errors", []) |
136 | 130 |
|
137 | 131 | def check_errors(keywords, *path): |
138 | 132 | """ Helper that looks for any of the given `keywords` in any of |
@@ -172,32 +166,16 @@ def check_errors(keywords, *path): |
172 | 166 | graphql_error["message"]) |
173 | 167 |
|
174 | 168 | # Check if API limit was exceeded |
175 | | - response_msg = r_json.get("message", "") |
| 169 | + response_msg = response.get("message", "") |
176 | 170 | if response_msg.startswith("You have exceeded"): |
177 | 171 | raise labelbox.exceptions.ApiLimitError(response_msg) |
178 | 172 |
|
179 | | - prisma_error = check_errors(["INTERNAL_SERVER_ERROR"], "extensions", |
180 | | - "code") |
181 | | - if prisma_error: |
182 | | - raise labelbox.exceptions.InternalServerError( |
183 | | - prisma_error["message"]) |
184 | | - |
185 | 173 | if len(errors) > 0: |
186 | 174 | logger.warning("Unparsed errors on query execution: %r", errors) |
187 | 175 | raise labelbox.exceptions.LabelboxError("Unknown error: %s" % |
188 | 176 | str(errors)) |
189 | 177 |
|
190 | | - # if we do return a proper error code, and didn't catch this above |
191 | | - # reraise |
192 | | - # this mainly catches a 401 for API access disabled for free tier |
193 | | - # TODO: need to unify API errors to handle things more uniformly |
194 | | - # in the SDK |
195 | | - if response.status_code != requests.codes.ok: |
196 | | - message = f"{response.status_code} {response.reason}" |
197 | | - cause = r_json.get('message') |
198 | | - raise labelbox.exceptions.LabelboxError(message, cause) |
199 | | - |
200 | | - return r_json["data"] |
| 178 | + return response["data"] |
201 | 179 |
|
202 | 180 | def upload_file(self, path: str) -> str: |
203 | 181 | """Uploads given path to local file. |
|
0 commit comments