use tonic::Code;

pub fn grpc_code_from_http_status_code(http_status_code: &str) -> Code {
    match http_status_code {
        "200" => Code::Ok,
        "302" => Code::AlreadyExists,
        "400" | "411" | "414" => Code::InvalidArgument,
        "401" | "407" => Code::Unauthenticated,
        "404" | "410" => Code::NotFound,
        "408" | "504" => Code::DeadlineExceeded,
        "402" | "409" | "412" | "417" | "423" => Code::FailedPrecondition,
        "416" => Code::OutOfRange,
        "500" => Code::Internal,
        "501" => Code::Unimplemented,
        "503" => Code::Unavailable,
        _ => Code::Unknown,
    }
}
