summaryrefslogtreecommitdiff
path: root/server/errors/models.go
diff options
context:
space:
mode:
authorMichael Hunteman <huntemanmt@gmail.com>2025-01-31 12:32:09 -0600
committerMichael Hunteman <huntemanmt@gmail.com>2025-01-31 12:32:09 -0600
commit6150d079ea06ba55e5f145b67f02065d94b757f9 (patch)
treed8994e3793fc55e052c7d7a780112b323128de13 /server/errors/models.go
parentff05f3941721de3ff343421968422d216d82e952 (diff)
Improve logging and error handling
Diffstat (limited to 'server/errors/models.go')
-rw-r--r--server/errors/models.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/server/errors/models.go b/server/errors/models.go
new file mode 100644
index 0000000..8f7d81c
--- /dev/null
+++ b/server/errors/models.go
@@ -0,0 +1,19 @@
+package errors
+
+import (
+ "encoding/json"
+ "fmt"
+)
+
+type AppError struct {
+ Status int `json:"code"`
+ Message json.RawMessage `json:"message"`
+}
+
+func NewAppError(status int, msg string) *AppError {
+ msgJson, err := json.Marshal(msg)
+ if err != nil {
+ msgJson = []byte(fmt.Sprintf(`{"message":"%s"}`, err.Error()))
+ }
+ return &AppError{status, msgJson}
+}