• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UPDATE_SERVICE_BUSINESS_ERROR_H
17 #define UPDATE_SERVICE_BUSINESS_ERROR_H
18 
19 #include <string>
20 #include <string_ex.h>
21 #include <vector>
22 
23 #include "call_result.h"
24 #include "error_message.h"
25 #include "json_builder.h"
26 #include "parcel.h"
27 
28 namespace OHOS::UpdateService {
29 struct BusinessError : public Parcelable {
30     std::string message;
31     CallResult errorNum = CallResult::SUCCESS;
32     std::vector<ErrorMessage> data;
33 
BuildBusinessError34     BusinessError &Build(CallResult callResult, const std::string &msg)
35     {
36         errorNum = callResult;
37         message = msg;
38         return *this;
39     }
40 
AddErrorMessageBusinessError41     BusinessError &AddErrorMessage(int32_t errorCode, const std::string &errorMessage)
42     {
43         ErrorMessage errMsg;
44         errMsg.errorCode = errorCode;
45         errMsg.errorMessage = errorMessage;
46         data.push_back(errMsg);
47         return *this;
48     }
49 
50     bool ReadFromParcel(Parcel &parcel);
51     bool Marshalling(Parcel &parcel) const override;
52     static BusinessError *Unmarshalling(Parcel &parcel);
53 };
54 } // namespace OHOS::UpdateService
55 #endif // UPDATE_SERVICE_BUSINESS_ERROR_H
56