Repository navigation
Expand file tree
/
Copy patherror.h
More file actions
135 lines (117 loc) · 3.94 KB
/
Copy patherror.h
File metadata and controls
135 lines (117 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
*/
#ifndef A2A_ERROR
#define A2A_ERROR
#include <exception>
#include <stdexcept>
#include <string>
#include "types.h"
namespace A2A {
/**
* @brief Base exception for A2A client-side errors.
* @note errorCode 使用 A2AErrorCode 或 HTTP 状态码(传输层错误)。
*/
struct A2AClientException : public std::runtime_error {
/** @brief Wire / SDK error code (A2AErrorCode or HTTP status). */
int errorCode;
/** @brief Human-readable error message. */
std::string message;
/**
* @brief Construct a client exception.
* @param[in] code Error code.
* @param[in] msg Error message.
*/
A2AClientException(int code, std::string msg);
/**
* @brief Create an exception_ptr wrapping A2AClientException.
* @param[in] code Error code.
* @param[in] message Error message.
* @return std::exception_ptr suitable for std::future::set_exception.
*/
static std::exception_ptr Make(int code, const std::string& message);
/**
* @brief Parse an A2AError from a caught exception.
* @param[in] e Exception to inspect.
* @param[out] out Populated A2AError on success.
* @return true if @p e is an A2AClientException.
*/
static bool TryParse(const std::exception& e, A2AError& out);
};
/**
* @brief Base exception for A2A server-side errors.
* @note statusCode 映射到 JSON-RPC / A2A wire error code (A2AErrorCode)。
*/
struct A2AServerError : public std::runtime_error {
/** @brief JSON-RPC / A2A error code returned to the client. */
int statusCode;
/**
* @brief Construct with internal-error code (-32603).
* @param[in] message Error description.
*/
explicit A2AServerError(const std::string& message)
: std::runtime_error(message),
statusCode(static_cast<int>(A2AErrorCode::JSONRPC_INTERNAL_ERROR))
{
}
/**
* @brief Construct with an explicit error code.
* @param[in] message Error description.
* @param[in] code A2AErrorCode value.
*/
explicit A2AServerError(const std::string& message, int code)
: std::runtime_error(message), statusCode(code)
{
}
};
/**
* @brief Thrown when the server does not implement the requested JSON-RPC method.
* @note 对应 JSON-RPC -32601 Method not found。
*/
struct MethodNotImplementedError : public A2AServerError {
/**
* @brief Construct a method-not-implemented error.
* @param[in] message Optional detail appended to the error text.
*/
explicit MethodNotImplementedError(const std::string& message = "This method is not implemented by the server")
: A2AServerError("Not Implemented operation Error: " + message,
static_cast<int>(A2AErrorCode::JSONRPC_METHOD_NOT_FOUND))
{
}
};
/**
* @brief Client exception for non-2xx HTTP responses.
*/
struct A2AClientHTTPError : public A2AClientException {
/** @brief HTTP status code from the transport layer. */
int statusCode;
/**
* @brief Construct an HTTP transport error.
* @param[in] httpStatusCode HTTP status code.
* @param[in] message Error description.
*/
explicit A2AClientHTTPError(int httpStatusCode, const std::string& message);
};
/**
* @brief Client exception for JSON-RPC or A2A protocol errors in a response body.
*/
struct A2AClientJSONError : public A2AClientException {
/**
* @brief Construct a JSON / protocol error.
* @param[in] code A2AErrorCode value from the response.
* @param[in] message Error description.
*/
explicit A2AClientJSONError(int code, const std::string& message);
};
/**
* @brief Client exception for request timeouts.
*/
struct A2AClientTimeoutError : public A2AClientException {
/**
* @brief Construct a timeout error.
* @param[in] message Error description.
*/
explicit A2AClientTimeoutError(const std::string& message);
};
} // namespace A2A
#endif