Move handler objects to common location to share with RMO

This commit is contained in:
Eli Ribble 2026-03-03 17:08:58 +00:00
parent 87fe5ec2e5
commit 0f6da8e25f
No known key found for this signature in database
33 changed files with 449 additions and 308 deletions

32
http/error_with_status.go Normal file
View file

@ -0,0 +1,32 @@
package http
import (
"fmt"
"net/http"
)
type ErrorWithStatus struct {
Message string
Status int
}
func (e *ErrorWithStatus) Error() string {
return e.Message
}
func NewError(mesg_format string, args ...any) *ErrorWithStatus {
return NewErrorStatus(http.StatusInternalServerError, mesg_format, args...)
}
func NewErrorMaybe(mesg_format string, err error, args ...any) *ErrorWithStatus {
if err == nil {
return nil
}
allArgs := append([]any{err}, args...)
return NewErrorStatus(http.StatusInternalServerError, mesg_format, allArgs...)
}
func NewErrorStatus(status int, mesg_format string, args ...any) *ErrorWithStatus {
w := fmt.Errorf(mesg_format, args...)
return &ErrorWithStatus{
Message: w.Error(),
Status: status,
}
}