Skip to content

Commit

Permalink
fix: avoid unwrap in main code
Browse files Browse the repository at this point in the history
Signed-off-by: Li Zhanhui <[email protected]>
  • Loading branch information
lizhanhui committed Mar 12, 2024
1 parent d329d77 commit fbdb9a8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,20 +626,16 @@ pub fn handle_response_status(
status: Option<Status>,
operation: &'static str,
) -> Result<(), ClientError> {
if status.is_none() {
return Err(ClientError::new(
ErrorKind::Server,
"server do not return status, this may be a bug",
operation,
));
}
let status = status.ok_or(ClientError::new(
ErrorKind::Server,
"server do not return status, this may be a bug",
operation,
))?;

let status = status.unwrap();
let status_code = Code::from_i32(status.code).unwrap();
if !status_code.eq(&Code::Ok) {
if status.code != Code::Ok as i32 {
return Err(
ClientError::new(ErrorKind::Server, "server return an error", operation)
.with_context("code", status_code.as_str_name())
.with_context("code", format!("{}", status.code))
.with_context("message", status.message),
);
}
Expand Down

0 comments on commit fbdb9a8

Please sign in to comment.