From 5b651488b081b65fda8a323f228e139adb79a35d Mon Sep 17 00:00:00 2001 From: Chia Date: Tue, 4 Aug 2026 19:58:52 +1200 Subject: Build AI gateway control plane and admin UI --- internal/apierror/apierror.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 internal/apierror/apierror.go (limited to 'internal/apierror') 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, + }, + }) +} -- cgit v1.2.3