Skip to content

Commit

Permalink
Merge pull request #1066 from guardrails-ai/dtam/better_unauthorized_…
Browse files Browse the repository at this point in the history
…errors

update unauthorized hub errors to include instructions
  • Loading branch information
CalebCourier authored Sep 12, 2024
2 parents 25a3935 + f884a33 commit 49fd8f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion guardrails/cli/server/hub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def get_validator_manifest(module_name: str):
logger.error(f"Failed to install hub://{module_name}")
sys.exit(1)
return module_manifest
except HttpError:
except HttpError as e:
if e.message == "Unauthorized":
logger.error(TOKEN_INVALID_MESSAGE)
raise
logger.error(f"Failed to install hub://{module_name}")
sys.exit(1)
except (ExpiredTokenError, InvalidTokenError) as e:
Expand Down
9 changes: 8 additions & 1 deletion guardrails/validator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ def _hub_inference_request(
}
req = requests.post(validation_endpoint, data=request_body, headers=headers)
if not req.ok:
logging.error(req.status_code)
if req.status_code == 401:
raise Exception(
"401: Remote Inference Unauthorized. Please run "
"`guardrails configure`. You can find a new"
" token at https://hub.guardrailsai.com/keys"
)
else:
logging.error(req.status_code)

return req.json()

Expand Down

0 comments on commit 49fd8f6

Please sign in to comment.