Skip to content

Commit fbb44d0

Browse files
authored
Merge pull request #152 from cnblogs/fix-serviceagent-handle-for-not-found
fix: handle not found correctly
2 parents 80ea1d7 + e531365 commit fbb44d0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/CqrsServiceAgent.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,13 @@ public async Task<CommandResponse<TResponse, ServiceAgentError>> PutCommandAsync
131131
/// <returns>The query result, can be null if item does not exists or status code is 404.</returns>
132132
public async Task<T?> GetItemAsync<T>(string url)
133133
{
134-
try
134+
var response = await HttpClient.GetAsync(url);
135+
return response.StatusCode switch
135136
{
136-
return await HttpClient.GetFromJsonAsync<T>(url);
137-
}
138-
catch (HttpRequestException e)
139-
{
140-
if (e.StatusCode == HttpStatusCode.NotFound)
141-
{
142-
return default;
143-
}
144-
145-
throw;
146-
}
137+
HttpStatusCode.OK => await response.Content.ReadFromJsonAsync<T>(),
138+
HttpStatusCode.NotFound => default,
139+
_ => default
140+
};
147141
}
148142

149143
/// <summary>

0 commit comments

Comments
 (0)