Skip to content

Commit 379021c

Browse files
authored
Write not-found.json to ExportedApi (#8252)
1 parent 95cca41 commit 379021c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

app/lib/package/api_export/api_exporter.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ class ApiExporter {
147147

148148
await synchronizePackageNameCompletionData();
149149

150+
await _api.notFound.write({
151+
'error': {
152+
'code': 'NotFound',
153+
'message': 'Package or version requested could not be found.',
154+
},
155+
'code': 'NotFound',
156+
'message': 'Package or version requested could not be found.',
157+
});
158+
150159
await _api.garbageCollect(allPackageNames);
151160
}
152161

app/lib/package/api_export/exported_api.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ final class ExportedApi {
6666
Duration(hours: 8),
6767
);
6868

69+
/// Interface for writing `/api/not-found.json` which is what the bucket will
70+
/// use as 404 response when serving a website.
71+
ExportedJsonFile<Map<String, Object?>> get notFound =>
72+
ExportedJsonFile<Map<String, Object?>>._(
73+
this,
74+
'/not-found.json',
75+
Duration(minutes: 10),
76+
);
77+
6978
/// Run garbage collection on the bucket.
7079
///
7180
/// This will remove all packages from `latest/` and `<runtimeVersion>/`,

0 commit comments

Comments
 (0)