summaryrefslogtreecommitdiff
path: root/internal/apierror
diff options
context:
space:
mode:
Diffstat (limited to 'internal/apierror')
-rw-r--r--internal/apierror/apierror.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/apierror/apierror.go b/internal/apierror/apierror.go
new file mode 100644
index 0000000..e88781a
--- /dev/null
+++ b/internal/apierror/apierror.go
@@ -0,0 +1,26 @@
+package apierror
+
+import (
+ "encoding/json"
+ "net/http"
+ "strconv"
+)
+
+type Error struct {
+ Status int
+ Type string
+ Message string
+}
+
+func Write(w http.ResponseWriter, err Error, requestID string) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("X-AIGW-Request-ID", requestID)
+ w.WriteHeader(err.Status)
+ _ = json.NewEncoder(w).Encode(map[string]any{
+ "error": map[string]string{
+ "code": strconv.Itoa(err.Status),
+ "type": err.Type,
+ "message": err.Message,
+ },
+ })
+}