Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const CodeSize = 15
CodeSize is the number of codes defined in the STL library. All codes defined by default are mapped from 0 to CodeSize - 1.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Example ¶
b := B().Code(Unknown).Msg("unknown error").Details("details")
err := b.Err()
str, _ := json.Marshal(err)
fmt.Println(string(str))
Output: {"code":"unknown","message":"unknown error"}
type Code ¶
type Code int
Code is the type that represents an error code. It can map to HTTP and gRPC codes.
const ( // Unknown is the default error code. Unknown Code = iota // Canceled indicates the operation was canceled or unavailable because it was cancelled. Canceled // InvalidArgument is used when the client sends invalid arguments. InvalidArgument // DeadlineExceeded means operation expired before completion. This doesn't necessarily mean that the operation failed. // It is possible that the operation succeeded but the deadline was exceeded. DeadlineExceeded // Unauthenticated is used when the client is not authenticated. Unauthenticated // NotFound is used when the requested resource is not found. NotFound // AlreadyExists is used when the resource already exists. AlreadyExists // Forbidden is used when the client is not authorized to perform the requested operation. Forbidden // ResourceExhausted is used when the client has exhausted some resource. ResourceExhausted // FailedPrecondition is used when the client sends a request that is not allowed in the current state. FailedPrecondition // Aborted is used when the client sends a request that cannot be completed due to a conflict e.g. a concurrency issue. Aborted // OutOfRange means that the operation was attempted past the valid range. OutOfRange // Internal is used when an internal error occurs. Internal Unavailable // DataLoss is used when the service has lost some data. DataLoss )
func (Code) MarshalJSON ¶
type Error ¶
type Error struct {
// Code is the error code of the error. When marshaled to JSON, it will be a string.
Code Code `json:"code"`
// Msg is the user-friendly message returned to the client.
Msg string `json:"message"`
// Details is the internal error message returned to the developer.
Details []any `json:"-"`
}
Click to show internal directories.
Click to hide internal directories.