-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
39 lines (33 loc) · 1.42 KB
/
errors.go
File metadata and controls
39 lines (33 loc) · 1.42 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
package relay
// -----------------------------------------------------------------------------
// Error Types
// -----------------------------------------------------------------------------
// ErrorCode represents a specific error condition in the mesh protocol.
type ErrorCode string
// Defined error codes.
const (
ErrorCodeNotFound ErrorCode = "not_found"
ErrorCodeAgentNotFound ErrorCode = "agent_not_found"
ErrorCodeClientNotFound ErrorCode = "client_not_found"
ErrorCodeSessionNotFound ErrorCode = "session_not_found"
ErrorCodeCapabilityMissing ErrorCode = "capability_missing"
ErrorCodeConnectionClosed ErrorCode = "connection_closed"
ErrorCodeTimeout ErrorCode = "timeout"
ErrorCodeInvalidMessage ErrorCode = "invalid_message"
ErrorCodeSessionOpenFailed ErrorCode = "session_open_failed"
ErrorCodeSessionCloseFailed ErrorCode = "session_close_failed"
ErrorCodeUnauthorized ErrorCode = "unauthorized"
)
// MeshError represents an error in the mesh system with a typed error code.
type MeshError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
}
// Error implements the error interface.
func (e *MeshError) Error() string {
return string(e.Code) + ": " + e.Message
}
// NewMeshError creates a new MeshError with the given code and message.
func NewMeshError(code ErrorCode, message string) *MeshError {
return &MeshError{Code: code, Message: message}
}