feat: ai-proxy support custom error handler by cover util.ErrorHandler (#1537)

This commit is contained in:
pepesi
2024-12-06 11:47:50 +08:00
committed by GitHub
parent 433227323d
commit 8f660211e3
6 changed files with 23 additions and 18 deletions

View File

@@ -13,8 +13,10 @@ const (
MimeTypeApplicationJson = "application/json"
)
func SendResponse(statusCode uint32, statusCodeDetails string, contentType, body string) error {
return proxywasm.SendHttpResponseWithDetail(statusCode, statusCodeDetails, CreateHeaders(HeaderContentType, contentType), []byte(body), -1)
type ErrorHandlerFunc func(statusCodeDetails string, err error) error
var ErrorHandler ErrorHandlerFunc = func(statusCodeDetails string, err error) error {
return proxywasm.SendHttpResponseWithDetail(500, statusCodeDetails, CreateHeaders(HeaderContentType, MimeTypeTextPlain), []byte(err.Error()), -1)
}
func CreateHeaders(kvs ...string) [][2]string {