Files
fm_be/internal/shared/pkg/apperrorsx/apperror.go
2026-07-16 22:16:45 +07:00

37 lines
618 B
Go

package apperrorsx
import "wucher/internal/transport/http/jsonapi"
// AppError is the canonical backend error contract used by translators and writers.
type AppError struct {
Status int
Code string
ErrorCode string
Title string
Message string
Detail any
Source *jsonapi.ErrorSource
Cause error
}
func (e *AppError) Error() string {
if e == nil {
return ""
}
if e.Message != "" {
return e.Message
}
if e.Cause != nil {
return e.Cause.Error()
}
return e.Code
}
func (e *AppError) WithCause(err error) *AppError {
if e == nil {
return nil
}
e.Cause = err
return e
}