Conversation
| { | ||
| case (int)HttpStatusCode.Forbidden: | ||
| throw new InvalidAPIKeyException($"request={request}"); | ||
| case (int)HttpStatusCode.NotFound: | ||
| throw new ResourceNotFoundException($"request={request}"); | ||
| case 429: // Quota Error | ||
| throw new QuotaException($"request={request}"); | ||
| default: | ||
| throw new BuffettCodeApiClientException($"request={request}"); | ||
| } | ||
| GetErrorResponseHandler.Handle(request, response); |
There was a problem hiding this comment.
getのエラーレスポンスの処理はこいつに任せます
There was a problem hiding this comment.
ちょっと名前が直感的じゃなく感じた。たぶん Get がどこにかかっているのかわからないから、「エラーレスポンスのハンドラ」を取得するように見える
「GETリクエストのエラー時のハンドラ」なら、 GetReqeustErrorHandler がわかりやすいかなと思うんだけどどうだろう (同じ問題はあるけど、 GetRequest という言葉はあるからまだましかなと)
There was a problem hiding this comment.
わかる GetRequestError にするわ
| Forbidden = HttpStatusCode.Forbidden, | ||
| NotFound = HttpStatusCode.NotFound, | ||
| BadRequest = HttpStatusCode.BadRequest, | ||
| ExceedingApiGatewayQuota = 429, |
There was a problem hiding this comment.
こいつは今使ってる HttpStatusCode に未定義でした、新しいやつには入ってるっぽいので .NET あげたら対応します
https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=net-6.0
There was a problem hiding this comment.
どのみち新しい.netframework入れたら TooManyRequests にするんだろうから、素直に TooManyRequests という名前にした方がいいと思う。もし ExceedingApiGatewayQuota を使いたいなら、 Forbidden や BadRequest をapplication specificな名前に変更した方がいいと思う
| case "{\"message\":\"Forbidden\"}": | ||
| throw new InvalidAPIKeyException($"request={request}"); |
There was a problem hiding this comment.
403 かつこのメッセージの時のみ InvalidAPIKeyException
| if (TestApiTokenErrorMessage.KnownErrorMessages.Contains(errorResponse.Content.ReadAsStringAsync().Result)) | ||
| { |
There was a problem hiding this comment.
CSむずかしすぎる… ReadAsStringAsync() ってどうasyncなの?
普通のプログラミング言語なら、コールバックを使うなり await するなりでまたなきゃいけないと思うけど、呼び出しを見ると同期してるように見える
There was a problem hiding this comment.
これまじで・・・もちろん await しないと使えないんだけど、 Result すると Task じゃなくて string がそのまま返ってくるのよね(詳細は追ってない
| } | ||
| else | ||
| { | ||
| throw new BuffettCodeApiClientException($"request={request}"); |
There was a problem hiding this comment.
知らないメッセージの 400 は BuffettCodeApiClientException
| switch (errorResponse.Content.ReadAsStringAsync().Result) | ||
| { | ||
| case "{\"message\":\"Forbidden\"}": | ||
| return new InvalidAPIKeyException($"request={request}"); |
There was a problem hiding this comment.
ネストしてるやつは return するようにしたのね
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuffettCodeAddinRibbonTests", "BuffettCodeAddinRibbonTests\BuffettCodeAddinRibbonTests.csproj", "{00A6A593-A87D-4DD2-8B06-8A36CFC6C3AA}" | ||
| EndProject | ||
| Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "SetupAddinRibbon32", "SetupAddinRibbon32\SetupAddinRibbon32.wixproj", "{E1016C59-0448-4BFA-B89D-BB3C960F1F16}" | ||
| ProjectSection(ProjectDependencies) = postProject |
There was a problem hiding this comment.
build が不安定だったので(成果物がないって言われる)、 Setup 系の build は各テストが終わってからにします
There was a problem hiding this comment.
見てる感じ、これでだいぶ安定した(なんでや・・・
| switch (errorResponse.Content.ReadAsStringAsync().Result) | ||
| { | ||
| case "{\"message\":\"Forbidden\"}": | ||
| return new InvalidAPIKeyException($"request={request}"); |
| return new TestAPIConstraintException($"request={request}"); | ||
| } | ||
| else | ||
| { | ||
| return new BuffettCodeApiClientException($"request={request}"); |
There was a problem hiding this comment.
こっちも return するようにしてあります
|
|
||
| static class InvalidAPIKeyErrorMessage | ||
| { | ||
| public const string ApiGatewayDefault = "{\"message\":\"Forbidden\"}"; |
There was a problem hiding this comment.
名前にまよったけど、一番現実に即した名前を付けてあります
| } | ||
|
|
||
| public class QuotaException : BuffettCodeApiClientException | ||
| public class DailyQuotaException : BuffettCodeApiClientException |
There was a problem hiding this comment.
AWS Gateway の daily quota によるものなので、 DailyQuotaException に rename しました
| else if (bce is DailyQuotaException) | ||
| { | ||
| message = "APIの実行回数が上限に達しました"; | ||
| message = "今日のAPIの実行回数が上限に達しました"; |
e9ea367 to
97b7b3a
Compare
to close #51