Files
online-backend/internal/appresult/error.go

45 lines
1.4 KiB
Go
Executable File

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")
ErrConflict = NewAppError(nil, "A user with this phone or username already exists.", "SE-00008")
ErrInvalidCode = NewAppError(nil, "Invalid or expired verification code.", "SE-00009")
ErrPasswordMismatch = NewAppError(nil, "Password confirmation does not match.", "SE-00010")
)
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
}