forked from phoenix/litellm-mirror
feat - add validation for existing customers
This commit is contained in:
parent
cdf32ebf0e
commit
24f0b82755
1 changed files with 64 additions and 38 deletions
|
@ -7833,12 +7833,14 @@ async def new_end_user(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
detail={"error": CommonProxyErrors.db_not_connected_error.value},
|
detail={"error": CommonProxyErrors.db_not_connected_error.value},
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
|
||||||
## VALIDATION ##
|
## VALIDATION ##
|
||||||
if data.default_model is not None:
|
if data.default_model is not None:
|
||||||
if llm_router is None:
|
if llm_router is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=422, detail={"error": CommonProxyErrors.no_llm_router.value}
|
status_code=422,
|
||||||
|
detail={"error": CommonProxyErrors.no_llm_router.value},
|
||||||
)
|
)
|
||||||
elif data.default_model not in llm_router.get_model_names():
|
elif data.default_model not in llm_router.get_model_names():
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -7878,6 +7880,30 @@ async def new_end_user(
|
||||||
)
|
)
|
||||||
|
|
||||||
return end_user_record
|
return end_user_record
|
||||||
|
except Exception as e:
|
||||||
|
if "Unique constraint failed on the fields: (`user_id`)" in str(e):
|
||||||
|
raise ProxyException(
|
||||||
|
message=f"Customer already exists, passed user_id={data.user_id}. Please pass a new user_id.",
|
||||||
|
type="bad_request",
|
||||||
|
code=400,
|
||||||
|
param="user_id",
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(e, HTTPException):
|
||||||
|
raise ProxyException(
|
||||||
|
message=getattr(e, "detail", f"Internal Server Error({str(e)})"),
|
||||||
|
type="internal_error",
|
||||||
|
param=getattr(e, "param", "None"),
|
||||||
|
code=getattr(e, "status_code", status.HTTP_500_INTERNAL_SERVER_ERROR),
|
||||||
|
)
|
||||||
|
elif isinstance(e, ProxyException):
|
||||||
|
raise e
|
||||||
|
raise ProxyException(
|
||||||
|
message="Internal Server Error, " + str(e),
|
||||||
|
type="internal_error",
|
||||||
|
param=getattr(e, "param", "None"),
|
||||||
|
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue