Repository navigation
Conversation
Non-200 responses were reported as a formatted string, so callers had to parse the message to branch on the status: wait and retry on 429, abort on an auth error. Matching on the message is fragile, since an error body can contain a stock code or wording that happens to include 401 or 429. *client.APIError carries the status code and the raw body. Services already wrap errors with %w, so errors.As reaches it from any service method. Error() keeps the exact previous format for callers that still match on the message.
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.
APIがエラーステータスを返した際に
*client.APIErrorを返すようにする。従来はフォーマット済み文字列だったため、利用側がステータスに応じて処理を分けるにはメッセージの文字列解析が必要だった(エラーボディに含まれる銘柄コード等の数字列が 401 や 429 と誤って一致する)。client.APIErrorがステータスコードと生のボディを保持する。各サービスは%wでラップしているため、サービスメソッド経由でもerrors.Asで取り出せるError()の書式は従来と完全に同一(API error: status=%d, body=%s)で、テストで固定IsRateLimitExceeded(429)、IsAuthError(401/403)、IsServerError(5xx)、StatusCodeを追加。403はAPIキー不正と契約プラン外アクセスの双方で返るため認証エラー側に含めている