[flutter_tools] Throw a tool exit when samples fetch fails (#52355)

This commit is contained in:
Zachary Anderson
2020-03-10 15:21:02 -07:00
committed by GitHub
parent 3d0082d054
commit 78b45fb1b2
2 changed files with 33 additions and 4 deletions

View File

@@ -239,13 +239,21 @@ class CreateCommand extends FlutterCommand {
}
final Uri snippetsUri = Uri.https(_snippetsHost, 'snippets/$sampleId.dart');
return utf8.decode(await _net.fetchUrl(snippetsUri));
final List<int> data = await _net.fetchUrl(snippetsUri);
if (data == null || data.isEmpty) {
return null;
}
return utf8.decode(data);
}
/// Fetches the samples index file from the Flutter docs website.
Future<String> _fetchSamplesIndexFromServer() async {
final Uri snippetsUri = Uri.https(_snippetsHost, 'snippets/index.json');
return utf8.decode(await _net.fetchUrl(snippetsUri, maxAttempts: 2));
final List<int> data = await _net.fetchUrl(snippetsUri, maxAttempts: 2);
if (data == null || data.isEmpty) {
return null;
}
return utf8.decode(data);
}
/// Fetches the samples index file from the server and writes it to
@@ -259,8 +267,7 @@ class CreateCommand extends FlutterCommand {
final String samplesJson = await _fetchSamplesIndexFromServer();
if (samplesJson == null) {
throwToolExit('Unable to download samples', exitCode: 2);
}
else {
} else {
outputFile.writeAsStringSync(samplesJson);
globals.printStatus('Wrote samples JSON to "$outputFilePath"');
}