mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package xgress_edge
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/hanzozt/channel/v4"
|
|
sdk "github.com/hanzozt/sdk-golang/zt/edge"
|
|
)
|
|
|
|
var _ error = (*EdgeError)(nil)
|
|
|
|
type EdgeError struct {
|
|
Message string `json:"message"`
|
|
Code uint32 `json:"code"`
|
|
Cause error `json:"cause"`
|
|
RetryHint sdk.RetryHint `json:"retryHint"`
|
|
}
|
|
|
|
func (e EdgeError) Error() string {
|
|
ret := fmt.Errorf("code: %d, message: %s", e.Code, e.Message).Error()
|
|
|
|
if e.Cause != nil {
|
|
ret += fmt.Sprintf(", Cause: %v", e.Cause)
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
func (e EdgeError) Unwrap() error {
|
|
return e.Cause
|
|
}
|
|
|
|
func (e EdgeError) ApplyToMsg(msg *channel.Message) {
|
|
errAsJson, err := json.Marshal(e)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
if len(errAsJson) > 0 {
|
|
msg.Headers.PutStringHeader(sdk.StructuredError, string(errAsJson))
|
|
msg.Headers.PutUint32Header(sdk.ErrorCodeHeader, e.Code)
|
|
}
|
|
}
|
|
|
|
// NewInvalidApiSessionTokenError creates a new EdgeError with the code ErrorInvalidApiSessionToken and the provided message.
|
|
func NewInvalidApiSessionTokenError(msg string) *EdgeError {
|
|
return &EdgeError{Message: msg, Code: sdk.ErrorCodeInvalidApiSession}
|
|
}
|
|
|
|
// NewInvalidApiSessionType creates an EdgeError with the ErrorInvalidApiSessionType" code and the provided message.
|
|
func NewInvalidApiSessionType(msg string) *EdgeError {
|
|
return &EdgeError{Message: msg, Code: sdk.ErrorCodeInvalidApiSessionType}
|
|
}
|