implement WhereAmIController#3
Closed
js00000000 wants to merge 5 commits intokyoangel:masterfrom
js00000000:master
Closed
implement WhereAmIController#3js00000000 wants to merge 5 commits intokyoangel:masterfrom js00000000:master
js00000000 wants to merge 5 commits intokyoangel:masterfrom
js00000000:master
Conversation
legnaoyk
reviewed
May 6, 2020
Comment on lines
+37
to
+46
| var response = new HttpResponseMessage(); | ||
| try | ||
| { | ||
| response = await _client.PostAsJsonAsync("http://ip-api.com/batch", ipList); | ||
| return await response.Content.ReadAsAsync<List<IpDetail>>(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| throw new Exception($"Status Code: {response.StatusCode}, Error message: {e}"); | ||
| } |
There was a problem hiding this comment.
這邊你先宣告 response 看起來是為了在exception的時候紀錄status code
其實你這邊的寫法是接了exception又補充資料 丟出exception.
但我覺得有更好的做法 就是讓例外直接丟,然後透過Action filter去外面寫下response的結果
aspnetcore有exceptionfilter可以寫
legnaoyk
reviewed
May 6, 2020
| var response = await _WhereAmIService.GetIp(); | ||
| var request = PrepareGetDetail(response.Ip); | ||
| var detail = await _WhereAmIService.GetIpDetail(request); | ||
| return $"Ip: {detail[0].Query}, Country Code: {detail[0].CountryCode}"; |
There was a problem hiding this comment.
你這邊回的是字串,而不是json, 可以直接回actionResult。可以試著用Anonymous type. 或定義回傳物件
legnaoyk
reviewed
May 6, 2020
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" /> |
There was a problem hiding this comment.
我想這就是為什麼你有httpclientFactory.Create()的靜態方法可以用的原因!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
implement WhereAmIController