validate method
Statically validates a Playground code snippet (analysis only; never
renders). Returns the diagnostics; throws ApiClientException on a
non-200 or a malformed response.
Implementation
Future<ApiValidationResult> validate(String code) async {
final response = await _http.post(
baseUrl.resolve('v1/validate'),
headers: {'content-type': 'application/json', ..._auth},
body: jsonEncode({'code': code}),
);
if (response.statusCode != 200) {
throw ApiClientException(_errorMessage(response.body), statusCode: response.statusCode);
}
try {
return ApiValidationResult.fromJson(jsonDecode(response.body) as Map<String, Object?>);
} on Object {
throw const ApiClientException('Malformed response from the validate API');
}
}