MCPcopy
hub / github.com/crewAIInc/crewAI / _validate_response

Method _validate_response

lib/cli/src/crewai_cli/command.py:40–81  ·  view source on GitHub ↗

Handle and display error messages from API responses. Args: response: The response from the Plus API.

(self, response: httpx.Response)

Source from the content-addressed store, hash-verified

38 raise AuthenticationRequiredError from None
39
40 def _validate_response(self, response: httpx.Response) -> None:
41 """Handle and display error messages from API responses.
42
43 Args:
44 response: The response from the Plus API.
45 """
46 try:
47 json_response = response.json()
48 except (json.JSONDecodeError, ValueError):
49 console.print(
50 "Failed to parse response from Enterprise API failed. Details:",
51 style="bold red",
52 )
53 console.print(f"Status Code: {response.status_code}")
54 console.print(
55 f"Response:\n{response.content.decode('utf-8', errors='replace')}"
56 )
57 raise SystemExit from None
58
59 if response.status_code == 422:
60 console.print(
61 "Failed to complete operation. Please fix the following errors:",
62 style="bold red",
63 )
64 for field, messages in json_response.items():
65 for message in messages:
66 console.print(
67 f"* [bold red]{field.capitalize()}[/bold red] {message}"
68 )
69 raise SystemExit
70
71 if not response.is_success:
72 console.print(
73 "Request to Enterprise API failed. Details:", style="bold red"
74 )
75 details = (
76 json_response.get("error")
77 or json_response.get("message")
78 or response.content.decode("utf-8", errors="replace")
79 )
80 console.print(f"{details}")
81 raise SystemExit

Callers 13

publishMethod · 0.80
deployMethod · 0.80
create_crewMethod · 0.80
get_crew_statusMethod · 0.80
get_crew_logsMethod · 0.80
list_triggersMethod · 0.80
execute_with_triggerMethod · 0.80
publishMethod · 0.80

Calls 3

jsonMethod · 0.45
printMethod · 0.45
getMethod · 0.45