Files
rogee b6d0af1a56
management-images / build-and-publish (push) Successful in 9m15s
docs: add one-click management deployment and image workflow
2026-09-16 17:57:05 +08:00

39 lines
772 B
Go

package management
import (
"database/sql"
"errors"
"fmt"
)
type AppError struct {
Status int
Code string
Message string
Fields map[string]any
}
func newAppError(status int, code, message string, fields map[string]any) *AppError {
return &AppError{Status: status, Code: code, Message: message, Fields: fields}
}
func (e *AppError) Error() string {
if e == nil {
return ""
}
return fmt.Sprintf("%s: %s", e.Code, e.Message)
}
func asAppError(err error) *AppError {
if err == nil {
return nil
}
if appErr, ok := err.(*AppError); ok {
return appErr
}
if errors.Is(err, sql.ErrNoRows) {
return newAppError(404, "RESOURCE_NOT_FOUND", "resource does not exist", nil)
}
return newAppError(500, "INTERNAL_ERROR", "internal server error", nil)
}