settings section
This commit is contained in:
41
internal/appresult/error.go
Executable file
41
internal/appresult/error.go
Executable file
@@ -0,0 +1,41 @@
|
||||
package appresult
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
var (
|
||||
ErrMissingParam = NewAppError(nil, "Required parameter is missing or invalid.", "SE-00001")
|
||||
ErrUnauthorized = NewAppError(nil, "Invalid credentials or unauthorized access.", "SE-00002")
|
||||
ErrNotFound = NewAppError(nil, "The requested resource was not found.", "SE-00003")
|
||||
ErrInternalServer = NewAppError(nil, "An internal server error occurred. Please try again later.", "SE-00004")
|
||||
ErrNotAcceptable = NewAppError(nil, "The request could not be processed.", "SE-00007")
|
||||
)
|
||||
|
||||
type AppError struct {
|
||||
Status bool `json:"status"`
|
||||
Err error `json:"-"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
}
|
||||
|
||||
func NewAppError(err error, message, code string) *AppError {
|
||||
return &AppError{
|
||||
Status: false,
|
||||
Err: err,
|
||||
Message: message,
|
||||
Code: code,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (e *AppError) Unwrap() error { return e.Err }
|
||||
|
||||
func (e *AppError) Marshal() []byte {
|
||||
marshal, err := json.Marshal(e)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return marshal
|
||||
}
|
||||
Reference in New Issue
Block a user