GroqException.fromResponse constructor
GroqException.fromResponse(
- Response response
Implementation
factory GroqException.fromResponse(http.Response response) {
final Map<String, dynamic> jsonBody =
json.decode(utf8.decode(response.bodyBytes, allowMalformed: true));
if (jsonBody.containsKey('error')) {
final groqError = GroqError.fromJson(jsonBody);
return GroqException(
statusCode: response.statusCode,
error: groqError,
);
} else {
// Handle cases where the response doesn't follow the standard Groq error structure
return GroqException(
statusCode: response.statusCode,
error: GroqError(message: 'Unknown error', type: 'unknown_error'),
);
}
}