Add backend foundation and config-driven workbench
This commit is contained in:
29
backend/internal/apperr/apperr.go
Normal file
29
backend/internal/apperr/apperr.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package apperr
|
||||
|
||||
import "errors"
|
||||
|
||||
type Error struct {
|
||||
Status int `json:"-"`
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func New(status int, code, message string) *Error {
|
||||
return &Error{
|
||||
Status: status,
|
||||
Code: code,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func From(err error) *Error {
|
||||
var appErr *Error
|
||||
if errors.As(err, &appErr) {
|
||||
return appErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user