Files
upstream-centrifugo/internal/tools/code_translate.go
upstream-mirror b352a9a30d
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s
snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:17:21 +05:00

42 lines
908 B
Go

package tools
import (
"net/http"
"github.com/centrifugal/centrifugo/v6/internal/configtypes"
"github.com/centrifugal/centrifuge"
)
func ConnectErrorToToHTTPResponse(err error, transforms []configtypes.ConnectCodeToHTTPResponseTransform) (configtypes.TransformedConnectErrorHttpResponse, bool) {
var code uint32
var body string
switch t := err.(type) {
case *centrifuge.Disconnect:
code = t.Code
body = t.Reason
case centrifuge.Disconnect:
code = t.Code
body = t.Reason
case *centrifuge.Error:
code = t.Code
body = t.Message
default:
}
if code > 0 {
for _, t := range transforms {
if t.Code != code {
continue
}
if t.To.Body == "" {
t.To.Body = body
}
return t.To, true
}
}
return configtypes.TransformedConnectErrorHttpResponse{
StatusCode: http.StatusInternalServerError,
Body: http.StatusText(http.StatusInternalServerError),
}, false
}