diff options
| author | Chia <Chia@93.nz> | 2026-08-04 19:58:52 +1200 |
|---|---|---|
| committer | Chia <Chia@93.nz> | 2026-08-04 20:43:23 +1200 |
| commit | 5b651488b081b65fda8a323f228e139adb79a35d (patch) | |
| tree | 08baf40efb8fe103b32721cd991ff712323e3173 /internal/apierror/apierror.go | |
Build AI gateway control plane and admin UI
Diffstat (limited to '')
| -rw-r--r-- | internal/apierror/apierror.go | 26 |
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, + }, + }) +} |
