Skip to content

Commit 349312c

Browse files
[PLT-821][PLT-822] Throw user readable errors when creating a custom embedding with an existing name or too few dimensions.
1 parent 7fac32f commit 349312c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

libs/labelbox/src/labelbox/adv_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from typing import Dict, Any, Optional, List, Callable
55
from urllib.parse import urlparse
6+
from labelbox.exceptions import ADVError
67

78
import requests
89
from requests import Session, Response
@@ -59,7 +60,12 @@ def _request(self,
5960
url,
6061
data=requests_data,
6162
headers=headers)
62-
response.raise_for_status()
63+
if response.status_code != requests.codes.ok:
64+
message = response.json().get('message')
65+
if message:
66+
raise ADVError(message)
67+
else:
68+
response.raise_for_status()
6369
return response.json()
6470

6571
def _send_ndjson(self,

libs/labelbox/src/labelbox/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def __init__(self, message, cause=None):
1515
def __str__(self):
1616
return self.message + str(self.args)
1717

18+
class ADVError(LabelboxError):
19+
"""Raised when ADV service returns an error for a REST call"""
20+
pass
1821

1922
class AuthenticationError(LabelboxError):
2023
"""Raised when an API key fails authentication."""

libs/labelbox/src/labelbox/schema/embedding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional, Callable, Dict, Any, List
22

33
from labelbox.adv_client import AdvClient
4+
from labelbox.exceptions import ADVError
45
from labelbox.pydantic_compat import BaseModel, PrivateAttr
56

67

0 commit comments

Comments
 (0)