• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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 PANDA_TOOLING_INSPECTOR_JSON_SERIALIZATION_JRPC_ERROR_H
17 #define PANDA_TOOLING_INSPECTOR_JSON_SERIALIZATION_JRPC_ERROR_H
18 
19 #include "json_serialization/serializable.h"
20 
21 namespace ark::tooling::inspector {
22 
23 enum class ErrorCode {
24     PARSE_ERROR = -32700,
25     INTERNAL_ERROR = -32603,
26     INVALID_PARAMS = -32602,
27     METHOD_NOT_FOUND = -32601,
28     INVALID_REQUEST = -32600,
29     SESSION_NOT_FOUND = -32001,
30     SERVER_ERROR = -32000,
31 };
32 
33 /// @brief Inspector error object with json-serialization capability.
34 class JRPCError final : public JsonSerializable {
35 public:
36     explicit JRPCError(std::string_view message, ErrorCode code = ErrorCode::INVALID_REQUEST)
code_(code)37         : code_(code), message_(message)
38     {
39     }
40 
41     explicit JRPCError(std::string &&message, ErrorCode code = ErrorCode::INVALID_REQUEST)
code_(code)42         : code_(code), message_(std::move(message))
43     {
44     }
45 
46     DEFAULT_COPY_SEMANTIC(JRPCError);
47     DEFAULT_MOVE_SEMANTIC(JRPCError);
48 
49     ~JRPCError() override = default;
50 
51     void Serialize(JsonObjectBuilder &builder) const override;
52 
53 private:
54     ErrorCode code_ {0};
55     std::string message_;
56 };
57 
58 }  // namespace ark::tooling::inspector
59 
60 #endif  // PANDA_TOOLING_INSPECTOR_JSON_SERIALIZATION_JRPC_ERROR_H
61