• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #[derive(Clone, Copy, PartialEq, Debug)]
15 pub(crate) enum Reason {
16     Default = 0,
17     TaskSurvivalOneMonth,
18     WaittingNetWorkOneday,
19     StoppedByNewFrontTask,
20     RunningTaskMeetLimits,
21     UserOperation,
22     AppBackgroundOrTerminate,
23     NetWorkOffline,
24     UnSupportedNetWorkType,
25     BuildClientFailed,
26     BuildRequestFailed,
27     GetFileSizeFailed,
28     ContinuousTaskTimeOut,
29     ConnectError,
30     RequestError,
31     UploadFileError,
32     RedirectError,
33     ProtocolError,
34     IoError,
35     UnSupportRangeRequest,
36     OthersError,
37 }
38 
39 impl From<u8> for Reason {
from(value: u8) -> Self40     fn from(value: u8) -> Self {
41         match value {
42             0 => Reason::Default,
43             1 => Reason::TaskSurvivalOneMonth,
44             2 => Reason::WaittingNetWorkOneday,
45             3 => Reason::StoppedByNewFrontTask,
46             4 => Reason::RunningTaskMeetLimits,
47             5 => Reason::UserOperation,
48             6 => Reason::AppBackgroundOrTerminate,
49             7 => Reason::NetWorkOffline,
50             8 => Reason::UnSupportedNetWorkType,
51             9 => Reason::BuildClientFailed,
52             10 => Reason::BuildRequestFailed,
53             11 => Reason::GetFileSizeFailed,
54             12 => Reason::ContinuousTaskTimeOut,
55             13 => Reason::ConnectError,
56             14 => Reason::RequestError,
57             15 => Reason::UploadFileError,
58             16 => Reason::RedirectError,
59             17 => Reason::ProtocolError,
60             18 => Reason::IoError,
61             19 => Reason::UnSupportRangeRequest,
62             _ => Reason::OthersError,
63         }
64     }
65 }
66 
67 impl Reason {
to_str(self) -> &'static str68     pub(crate) fn to_str(self) -> &'static str {
69         match self {
70             Reason::Default => "",
71             Reason::TaskSurvivalOneMonth => "The task has not been completed for a month yet",
72             Reason::WaittingNetWorkOneday => "The task waiting for network recovery has not been completed for a day yet",
73             Reason::StoppedByNewFrontTask => "Stopped by a new front task",
74             Reason::RunningTaskMeetLimits => "Too many task in running state",
75             Reason::UserOperation => "User operation",
76             Reason::AppBackgroundOrTerminate => "The app is background or terminate",
77             Reason::NetWorkOffline => "NetWork is offline",
78             Reason::UnSupportedNetWorkType => "NetWork type not meet the task config",
79             Reason::BuildClientFailed => "Build client error",
80             Reason::BuildRequestFailed => "Build request error",
81             Reason::GetFileSizeFailed => "Failed because cannot get the file size from the server and the precise is setted true by user",
82             Reason::ContinuousTaskTimeOut => "Continuous processing task time out",
83             Reason::ConnectError => "Connect error",
84             Reason::RequestError => "Request error",
85             Reason::UploadFileError => "There are some files upload failed",
86             Reason::RedirectError => "Redirect error",
87             Reason::ProtocolError => "Http protocol error",
88             Reason::IoError => "Io Error",
89             Reason::UnSupportRangeRequest => "The server is not support range request",
90             Reason::OthersError => "Some other error occured",
91         }
92     }
93 }
94