Skip to content

Commit

Permalink
市区町村マスタの取得に失敗した場合、ApiErrorとしてエラーメッセージをParseResultに含めるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
YuukiToriyama committed Nov 23, 2023
1 parent 00ff3c3 commit 832b4bf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ pub async fn parse<T: Api>(api: T, input: &str) -> ParseResult {
Some(result) => result,
};
// その市町村の町名リストを取得
let city = api
.get_city_master(prefecture_name, city_name)
.await
.unwrap();
let city = match api.get_city_master(prefecture_name, city_name).await {
Err(error) => return ParseResult {
address: Address::new(prefecture_name, city_name, "", rest),
error: Some(error)
},
Ok(result) => result
};
// 町名を特定
let (rest, town_name) = match read_town(rest, city) {
None => {
Expand Down Expand Up @@ -132,6 +135,11 @@ mod parser_tests {
);
}

#[tokio::test]
async fn parse_mocked_fail_市区町村マスタの取得に失敗する() {
// TODO: ApiMockの仕様を修正しないとこのテストコードは書けない
}

#[tokio::test]
async fn parse_mocked_fail_町名が間違っている場合() {
let api = ApiMock { should_fail: false };
Expand Down

0 comments on commit 832b4bf

Please sign in to comment.