mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-12 04:54:45 +00:00
feat: scaffold traefik-llmgateway plugin skeleton with manifest
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package traefikllmgateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
// writeOAIError writes an OpenAI-compatible error envelope:
|
||||
// {"error":{"message":...,"type":...,"code":...}}.
|
||||
func writeOAIError(w http.ResponseWriter, status int, errType, msg string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"error": map[string]any{"message": msg, "type": errType, "code": status},
|
||||
})
|
||||
}
|
||||
|
||||
// recoverPanic recovers a panic from a handler, logs it, and writes a 500
|
||||
// error envelope instead of letting the panic escape ServeHTTP.
|
||||
func recoverPanic(w http.ResponseWriter, g *Gateway) {
|
||||
if rec := recover(); rec != nil {
|
||||
g.errorf("panic recovered: %v\n%s", rec, debug.Stack())
|
||||
writeOAIError(w, http.StatusInternalServerError, "server_error", "internal error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user