-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from YuukiToriyama/feature/return-parse-error-i…
…f-a-panic-occurs パースエラーが発生した場合、エラーの内容をパース結果と共に返すようにした
- Loading branch information
Showing
4 changed files
with
133 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::fmt::{Display, Formatter}; | ||
|
||
use serde::Serialize; | ||
|
||
#[derive(Serialize, Debug, PartialEq)] | ||
pub struct Error { | ||
pub error_type: String, | ||
pub error_message: String, | ||
} | ||
|
||
impl Error { | ||
pub fn new_parse_error(parse_error_kind: ParseErrorKind) -> Self { | ||
Error { | ||
error_type: "ParseError".to_string(), | ||
error_message: parse_error_kind.to_string(), | ||
} | ||
} | ||
pub fn new_resource_unavailable_error(message: &str) -> Self { | ||
Error { | ||
error_type: "ResourceUnavailableError".to_string(), | ||
error_message: message.to_string(), | ||
} | ||
} | ||
} | ||
|
||
pub enum ParseErrorKind { | ||
PREFECTURE, | ||
CITY, | ||
TOWN, | ||
} | ||
|
||
impl Display for ParseErrorKind { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
let label = match *self { | ||
Self::PREFECTURE => "都道府県", | ||
Self::CITY => "市区町村", | ||
Self::TOWN => "町名", | ||
}; | ||
write!(f, "一致する{}がありませんでした", label) | ||
} | ||
} |
This file contains 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
This file contains 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