init push
This commit is contained in:
36
internal/shared/pkg/apperrorsx/apperror.go
Normal file
36
internal/shared/pkg/apperrorsx/apperror.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user