51 lines
1.9 KiB
Go
Executable File
51 lines
1.9 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")
|
|
ErrForbidden = NewAppError(nil, "Sana rugsat yok.", "SE-00011")
|
|
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")
|
|
ErrDuplicate = NewAppError(nil, "A record with these values already exists.", "SE-00012")
|
|
ErrRoleInUse = NewAppError(nil, "The role is still assigned to users.", "SE-00013")
|
|
ErrLastSuperadmin = NewAppError(nil, "The last superadmin cannot be removed or demoted.", "SE-00014")
|
|
ErrUnknownRole = NewAppError(nil, "Role not found.", "SE-00015")
|
|
ErrSystemRole = NewAppError(nil, "System roles cannot be deleted or have their scope changed.", "SE-00016")
|
|
)
|
|
|
|
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
|
|
}
|