MCPcopy
hub / github.com/gpustack/gpustack / raise_errors

Function raise_errors

gpustack/api/exceptions.py:105–147  ·  view source on GitHub ↗
(response: httpx.Response)

Source from the content-addressed store, hash-verified

103
104
105def raise_errors(response: httpx.Response):
106 try:
107 response_json = response.json()
108 # Compatible with OpenAI API error format
109 if "error" in response_json and isinstance(response_json["error"], dict):
110 response_json = response_json["error"]
111 if "type" in response_json and isinstance(response_json["type"], str):
112 response_json["reason"] = response_json["type"]
113 error = ErrorResponse.model_validate(response_json)
114 except Exception:
115 raise HTTPException(response.status_code, "Unknown", response.text)
116
117 if response.status_code == status.HTTP_404_NOT_FOUND:
118 raise NotFoundException(error.message)
119
120 if (
121 response.status_code == status.HTTP_409_CONFLICT
122 and error.reason == "AlreadyExists"
123 ):
124 raise AlreadyExistsException(error.message)
125
126 if response.status_code == status.HTTP_401_UNAUTHORIZED:
127 raise UnauthorizedException(error.message)
128
129 if response.status_code == status.HTTP_403_FORBIDDEN:
130 raise ForbiddenException(error.message)
131
132 if response.status_code == HTTP_422_UNPROCESSABLE:
133 raise InvalidException(error.message)
134
135 if response.status_code == status.HTTP_400_BAD_REQUEST:
136 raise BadRequestException(error.message)
137
138 if response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR:
139 raise InternalServerErrorException(error.message)
140
141 if response.status_code == status.HTTP_503_SERVICE_UNAVAILABLE:
142 raise ServiceUnavailableException(error.message)
143
144 if response.status_code == status.HTTP_504_GATEWAY_TIMEOUT:
145 raise GatewayTimeoutException(error.message)
146
147 raise HTTPException(error.code, error.reason, error.message)
148
149
150class ErrorResponse(BaseModel):

Callers 2

raise_if_response_errorFunction · 0.85

Calls 2

HTTPExceptionClass · 0.85
jsonMethod · 0.80

Tested by

no test coverage detected