Skip to content

Commit 69bf886

Browse files
committed
Prevent db generation if a spec update fails
1 parent 783713e commit 69bf886

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

DevProxy.Abstractions/Data/MSGraphDb.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,18 @@ public async Task<int> GenerateDbAsync(bool skipIfUpdatedToday, CancellationToke
6666
return 1;
6767
}
6868

69-
var isApiModified = await UpdateOpenAPIGraphFilesIfNecessaryAsync(appFolder, cancellationToken);
69+
var (isApiModified, errorCount) = await UpdateOpenAPIGraphFilesIfNecessaryAsync(appFolder, cancellationToken);
70+
71+
if (errorCount > 0)
72+
{
73+
_logger.LogWarning("Unable to generate Microsoft Graph database");
74+
return 1;
75+
}
7076

7177
if (!isApiModified)
7278
{
7379
UpdateLastWriteTime(dbFileInfo);
74-
_logger.LogDebug("Updated the last-write-time of Microsoft Graph database {File}", dbFileInfo);
80+
_logger.LogDebug("Updated the last-write-time attribute of Microsoft Graph database {File}", dbFileInfo);
7581
_logger.LogInformation("Microsoft Graph database is already updated");
7682
return 1;
7783
}
@@ -184,11 +190,12 @@ private async Task FillDataAsync(CancellationToken cancellationToken)
184190
_logger.LogInformation("Inserted {EndpointCount} endpoints in the database", i);
185191
}
186192

187-
private async Task<bool> UpdateOpenAPIGraphFilesIfNecessaryAsync(string folder, CancellationToken cancellationToken)
193+
private async Task<(bool isApiUpdated, int errors)> UpdateOpenAPIGraphFilesIfNecessaryAsync(string folder, CancellationToken cancellationToken)
188194
{
189195
_logger.LogInformation("Checking for updated OpenAPI files...");
190196

191197
var isApiUpdated = false;
198+
var errorCount = 0;
192199

193200
foreach (var version in graphVersions)
194201
{
@@ -212,10 +219,11 @@ private async Task<bool> UpdateOpenAPIGraphFilesIfNecessaryAsync(string folder,
212219
}
213220
catch (Exception ex)
214221
{
222+
errorCount++;
215223
_logger.LogError(ex, "Error updating OpenAPI files");
216224
}
217225
}
218-
return isApiUpdated;
226+
return (isApiUpdated, errorCount);
219227
}
220228

221229
private async Task<bool> DownloadOpenAPIFileAsync(string url, FileInfo yamlFile, FileInfo etagFile, CancellationToken cancellationToken)
@@ -237,7 +245,7 @@ private async Task<bool> DownloadOpenAPIFileAsync(string url, FileInfo yamlFile,
237245
if (response.StatusCode == HttpStatusCode.NotModified)
238246
{
239247
UpdateLastWriteTime(yamlFile);
240-
_logger.LogDebug("Updated the last-write-time of OpenAPI file {File}", yamlFile);
248+
_logger.LogDebug("Updated the last-write-time attribute of OpenAPI file {File}", yamlFile);
241249
return false;
242250
}
243251

0 commit comments

Comments
 (0)