Skip to content

Commit

Permalink
ingest WriteKeyStreamLocator: better error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Nov 9, 2024
1 parent cd0232b commit c7b5a7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ingest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (r *Router) WriteKeyStreamLocator(loc *StreamCredentials, _ bool) *StreamWi
binding := r.repository.GetData().getStreamByKeyId(parts[0])
if binding != nil {
if loc.IngestType != IngestTypeWriteKeyDefined && binding.KeyType != string(loc.IngestType) {
r.Errorf("[stream: %s]%s invalid key type found %s, expected %s", binding.StreamId, loc.String(), binding.KeyType, loc.IngestType)
r.Errorf("[stream: %s]%s invalid key type found %s", binding.StreamId, loc.String(), binding.KeyType)
} else if !r.checkHash(binding.Hash, parts[1]) {
r.Errorf("[stream: %s]%s invalid key secret", binding.StreamId, loc.String())
} else {
Expand Down
10 changes: 8 additions & 2 deletions ingest/router_batch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/jitsucom/bulker/jitsubase/jsonorder"
"github.com/jitsucom/bulker/jitsubase/utils"
"github.com/jitsucom/bulker/jitsubase/uuid"
"io"
"net/http"
"strings"
)
Expand Down Expand Up @@ -40,11 +41,16 @@ func (r *Router) BatchHandler(c *gin.Context) {
if strings.Contains(c.GetHeader("Content-Encoding"), "gzip") {
bodyReader, err = gzip.NewReader(bodyReader)
}
var body []byte
if err == nil {
err = jsonorder.NewDecoder(bodyReader).Decode(&payload)
body, err = io.ReadAll(bodyReader)
_ = bodyReader.Close()
}
if err == nil {
err = jsonorder.Unmarshal(body, &payload)
}
if err != nil {
err = fmt.Errorf("Client Ip: %s: %v", utils.NvlString(c.GetHeader("X-Real-Ip"), c.GetHeader("X-Forwarded-For"), c.ClientIP()), err)
err = fmt.Errorf("Client Ip: %s: %v Body:\n%s", utils.NvlString(c.GetHeader("X-Real-Ip"), c.GetHeader("X-Forwarded-For"), c.ClientIP()), err, string(body))
rError = r.ResponseError(c, http.StatusBadRequest, "error parsing message", false, err, true)
return
}
Expand Down

0 comments on commit c7b5a7b

Please sign in to comment.